|
 |
انجمن را در گوگل محبوب کنيد :
|
تبليغات سايت |
|
 |
۱۲-۲۵-۱۳۸۸, ۱۲:۰۶ بعد از ظهر
|
#1 (لینک دائم)
|
Administrator
تاريخ عضويت: خرداد ۱۳۸۷
محل سكونت: تهران-کرج!
پست ها: 3,465
تشكرها: 754
16,337 تشكر در 3,127 پست
My Mood:
|
برنامه معمای 8 (پازل 8)
كد:
#include
#include
#include
#include
#include
#define TRUE 1
#define FALSE 0
unsigned int a,b,c,d,e,f,g,h;
void main(void)
{
unsigned char chk_crash(unsigned char,unsigned char,unsigned char);
void draw_puzzle(void);
clrscr();
for (a=1;a<=8;a++);
for (b=1;b<=8;b++);
if (chk_crash(a,b,1))
for (c=1;c<=8;c++)
if ((chk_crash(c,b,1)) && (chk_crash(c,a,2)))
for (d=1;d<=8;d++)
if ((chk_crash(d,c,1)) && (chk_crash(d,b,2)) && (chk_crash(d,a,3)))
for(e=1;e<=8;e++)
if ((chk_crash(e,d,1)) && (chk_crash(e,c,2)) && (chk_crash(e,b,3)) && (chk_crash(e,a,4)))
for (f=1;f<=8;f++)
if ((chk_crash(f,e,1)) && (chk_crash(f,d,2)) && (chk_crash(f,c,3)) && (chk_crash(f,b,4)) && (chk_crash(f,a,5)))
for (g=1;g<=8;g++)
if ((chk_crash(g,f,1)) && (chk_crash(g,e,2)) && (chk_crash(g,d,3)) && (chk_crash(g,c,4)) && (chk_crash(g,b,5)) && (chk_crash(g,a,6)))
for (h=1;h<=8;h++)
if ((chk_crash(h,g,1)) && (chk_crash(h,f,2)) && (chk_crash(h,e,3)) && (chk_crash(h,d,4)) && (chk_crash(h,c,5)) && (chk_crash(h,b,6)) && (chk_crash(h,a,7)))
{
draw_puzzle();
getch();
}
getch();
}
unsigned char chk_crash(unsigned char i,unsigned char j,unsigned char d)
{
if ((i==j) || (abs(i-j)==d))
return(FALSE);
else
return(TRUE);
}
void draw_puzzle(void)
{
unsigned char a1,b1,a2,b2,i,v;
clrscr();
for (a1=1;a1<=16;a1++)
for (b1=18;b<=65;b1++)
{
gotoxy(b1,a1+d);
a2=(a1-1)/2+1;
b2=(b1-18)/6+1;
if (((a2+b2)%2)==0)
textcolor(11);
else
textcolor(1);
cprintf("A\0");
for (i=0;i<8;i++)
{
switch(i)
{
case 0:{v=a;break;}
case 1:{v=b;break;}
case 2:{v=c;break;}
case 3:{v=d;break;}
case 4:{v=e;break;}
case 5:{v=f;break;}
case 6:{v=g;break;}
case 7:{v=h;break;}
}
gotoxy(15+6*v,5+i*2);
cprintf("*\0");
}
}
}
|
|
|
از Astaraki تشكر كرده اند:
|
astronomer (۰۷-۱۷-۱۳۹۲), ayfer.a11 (۰۸-۴-۱۳۹۰), delsa s (۰۸-۲-۱۳۹۲), elit (۰۷-۲۳-۱۳۹۱), Goback (۰۵-۲۱-۱۳۸۹), khokho (۰۱-۲۱-۱۳۹۰), norozi_a_2007 (۰۳-۱۷-۱۳۹۱), pincode (۰۸-۴-۱۳۹۲), rouhallah (۱۲-۲۹-۱۳۸۸), Sahebi (۰۱-۱۱-۱۳۸۹), samane_89 (۱۲-۲۸-۱۳۸۹), وجیهه نصر (۰۸-۷-۱۳۹۲), voice (۰۸-۴-۱۳۹۲), zari11368 (۱۲-۱۷-۱۳۹۰) |
|
#ADS
|
نشان دهنده تبلیغات
تبليغگر
تاريخ عضويت: -
محل سكونت: -
سن: 2010
پست ها: -
|
|
|
|
۱۲-۲۵-۱۳۸۸, ۱۲:۳۲ بعد از ظهر
|
#2 (لینک دائم)
|
Administrator
تاريخ عضويت: خرداد ۱۳۸۷
محل سكونت: تهران-کرج!
پست ها: 3,465
تشكرها: 754
16,337 تشكر در 3,127 پست
My Mood:
|
حالت خطی
8puzzle
كد:
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <map>
#include <queue>
using namespace std;
map <string , int> m;
queue < string > qs;
queue < int > qc,qd;
//struct state{
// string s;
// int c,d;
//};
//queue <state> q;
void puzzle(int cur,string s){
if (m.find(s)==m.end()){
m[s]=qd.front();
if (cur-1>=0 && cur-1<=8 && cur!=6 && cur!=3){
string temp=s;
{char t=temp[cur]; temp[cur]=temp[cur-1]; temp[cur-1]=t; }
qc.push(cur-1);
qd.push(m[s]+1);
qs.push(temp);
}
if (cur+1>=0 && cur+1<=8 && cur!=2 && cur!=5){
string temp=s;
{char t=temp[cur]; temp[cur]=temp[cur+1]; temp[cur+1]=t; }
qc.push(cur+1);
qd.push(m[s]+1);
qs.push(temp);
}
if (cur-3>=0 && cur-3<=8){
string temp=s;
{char t=temp[cur]; temp[cur]=temp[cur-3]; temp[cur-3]=t; }
qc.push(cur-3);
qs.push(temp);
qd.push(m[s]+1);
}
if (cur+3>=0 && cur+3<=8){
string temp=s;
{char t=temp[cur]; temp[cur]=temp[cur+3]; temp[cur+3]=t; }
qc.push(cur+3);
qs.push(temp);
qd.push(m[s]+1);
}
}
qs.pop();
qc.pop();
qd.pop();
}
int main () {
clock_t cl=clock();
ifstream in ("8puzzle.in");
qs.push("123456780");
qc.push(8);
qd.push(0);
while (!qs.empty())
puzzle(qc.front(),qs.front());
int t;
for (in >> t;t>0;--t){
string s,temp;
for (int i=0;i<3;++i)
for (int j=0;j<3;++j){
in >> temp;
if (temp=="-1")
temp="0";
s+=temp;
}
if (m.find(s)==m.end())
cout << "Impossible" << endl;
else
cout << m[s] << endl;
}
cout << "time: " << (clock()-cl) * 0.001 << endl;
return 0;
}
|
|
|
از Astaraki تشكر كرده اند:
|
astronomer (۰۷-۱۷-۱۳۹۲), ayfer.a11 (۰۸-۴-۱۳۹۰), elit (۰۷-۲۳-۱۳۹۱), green_Dream (۱۲-۲۸-۱۳۸۸), khokho (۰۱-۲۱-۱۳۹۰), pincode (۰۸-۴-۱۳۹۲), rouhallah (۱۲-۲۹-۱۳۸۸), Sahebi (۰۱-۱۱-۱۳۸۹), samane_89 (۱۲-۲۸-۱۳۸۹), وجیهه نصر (۰۸-۷-۱۳۹۲), voice (۰۸-۴-۱۳۹۲), zari11368 (۱۲-۱۷-۱۳۹۰) |
۰۱-۲۴-۱۳۹۳, ۰۹:۳۹ قبل از ظهر
|
#3 (لینک دائم)
|
عضو جدید
تاريخ عضويت: فروردين ۱۳۹۳
پست ها: 1
تشكرها: 0
0 تشكر در 0 پست
|
نقل قول:
نوشته اصلي بوسيله reyhane
كد:
#include
#include
#include
#include
#include
#define true 1
#define false 0
unsigned int a,b,c,d,e,f,g,h;
void main(void)
{
unsigned char chk_crash(unsigned char,unsigned char,unsigned char);
void draw_puzzle(void);
clrscr();
for (a=1;a<=8;a++);
for (b=1;b<=8;b++);
if (chk_crash(a,b,1))
for (c=1;c<=8;c++)
if ((chk_crash(c,b,1)) && (chk_crash(c,a,2)))
for (d=1;d<=8;d++)
if ((chk_crash(d,c,1)) && (chk_crash(d,b,2)) && (chk_crash(d,a,3)))
for(e=1;e<=8;e++)
if ((chk_crash(e,d,1)) && (chk_crash(e,c,2)) && (chk_crash(e,b,3)) && (chk_crash(e,a,4)))
for (f=1;f<=8;f++)
if ((chk_crash(f,e,1)) && (chk_crash(f,d,2)) && (chk_crash(f,c,3)) && (chk_crash(f,b,4)) && (chk_crash(f,a,5)))
for (g=1;g<=8;g++)
if ((chk_crash(g,f,1)) && (chk_crash(g,e,2)) && (chk_crash(g,d,3)) && (chk_crash(g,c,4)) && (chk_crash(g,b,5)) && (chk_crash(g,a,6)))
for (h=1;h<=8;h++)
if ((chk_crash(h,g,1)) && (chk_crash(h,f,2)) && (chk_crash(h,e,3)) && (chk_crash(h,d,4)) && (chk_crash(h,c,5)) && (chk_crash(h,b,6)) && (chk_crash(h,a,7)))
{
draw_puzzle();
getch();
}
getch();
}
unsigned char chk_crash(unsigned char i,unsigned char j,unsigned char d)
{
if ((i==j) || (abs(i-j)==d))
return(false);
else
return(true);
}
void draw_puzzle(void)
{
unsigned char a1,b1,a2,b2,i,v;
clrscr();
for (a1=1;a1<=16;a1++)
for (b1=18;b<=65;b1++)
{
gotoxy(b1,a1+d);
a2=(a1-1)/2+1;
b2=(b1-18)/6+1;
if (((a2+b2)%2)==0)
textcolor(11);
else
textcolor(1);
cprintf("a\0");
for (i=0;i<8;i++)
{
switch(i)
{
case 0:{v=a;break;}
case 1:{v=b;break;}
case 2:{v=c;break;}
case 3:{v=d;break;}
case 4:{v=e;break;}
case 5:{v=f;break;}
case 6:{v=g;break;}
case 7:{v=h;break;}
}
gotoxy(15+6*v,5+i*2);
cprintf("*\0");
}
}
}
|
سلام
چرا برنامه اجرا نمیشه؟همش ارور میده؟
|
|
|
۰۲-۱-۱۳۹۳, ۰۷:۳۴ قبل از ظهر
|
#4 (لینک دائم)
|
عضو جدید
تاريخ عضويت: ارديبهشت ۱۳۹۳
پست ها: 1
تشكرها: 0
0 تشكر در 0 پست
|
in codi k gozashti be zabune C#e? mishe ye tozihiam bedi?
|
|
|
كاربران در حال ديدن تاپيک: 1 (0 عضو و 1 مهمان)
|
|
قوانين ارسال
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
كدهاي HTML غير فعال است
|
|
|
زمان محلي شما با تنظيم GMT +3.5 هم اکنون ۰۲:۲۰ قبل از ظهر ميباشد.
|
Inactive Reminders By Icora Web Design
|