摘要:输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数。如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块。(题意是让求连在一起的块有几个,图见书本)SamInput6 100100 001010 000000 110000 111000 010100 1 #include 2 using namespace std; 3 const int MAXN=30; 4 int mat[MAXN][MAXN],vis[MAXN][MAXN]; 5 void dfs(int x,int y) 6 { 7 if(!mat[x][y]||vis[x][y])//当...
阅读全文
摘要:#include#includeusing namespace std;const int MAXN=1000+10;int n,target[MAXN];int main(){ while(scanf("%d",&n)==1) { stack s; int A=1,B=1; for(int i=1;i<=n;i++) scanf("%d",&target[i]); int ok=1; while(B<=n) { if(A==target[B]) {A++; B++; } else if(!s.em...
阅读全文
摘要:输入26以内的数字 输出一个字母组成的金字塔 本来想用c++写 到一半发现不能控制字符输出 然后又用的printf 显得有点乱 还有就是把第一个i=100,改成i=101输出的程序有问题 不知道该怎么解决 现放出代码 1 #include 2 using namespace std; 3 int main() 4 { 5 int i,j,k,x; 6 char f[100]; 7 cin>>x; 8 for (i=1;i0;j--)13 cout0;k--)17 printf("%c",f[k]);18 ...
阅读全文
摘要:奇偶数分离时间限制:3000 ms | 内存限制:65535 KB难度:1描述有一个整型偶数n(2 2 using namespace std; 3 int main() 4 { 5 int i,j,n,t; 6 cin>>i; 7 while(i--) 8 { 9 cin>>n;10 for(j=1;j<n;j=j+2)11 cout<<j<<" ";12 cout<<endl;13 for(t=2;t<=n;t=t+2)14 cout<<t...
阅读全文
摘要:Asimplemathematicalformulaforeiswherenisallowedtogotoinfinity.Thiscanactuallyyieldveryaccurateapproximationsofeusingrelativelysmallvaluesofn.OutputOutputtheapproximationsofegeneratedbytheaboveformulaforthevaluesofnfrom0to9.Thebeginningofyouroutputshouldappearsimilartothatshownbelow.ExampleOutputne--
阅读全文
摘要:Larrygraduatedthisyearandfinallyhasajob.He'smakingalotofmoney,butsomehowneverseemstohaveenough.Larryhasdecidedthatheneedstograbholdofhisfinancialportfolioandsolvehisfinancingproblems.Thefirststepistofigureoutwhat'sbeengoingonwithhismoney.Larryhashisbankaccountstatementsandwantstoseehowmuchmo
阅读全文
摘要:1 #include 2 using namespace std; 3 int main() 4 { 5 float c; 6 while((cin>>c)&&c!=0) 7 { 8 float sum=0; 9 int n=2;10 while(sum<c)11 {12 sum=sum+1.00/n;13 n++;14 }15 cout<<n-2;16 }17 return 0;18 }View Code Howfarcanyoumakeastackofcardsoverhangatable?Ifyouhaveonec...
阅读全文
摘要:http://acm.nyist.net/JudgeOnline/problem.php?pid=5描述Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110110’ while the pattern string A is ‘11’, you should output 3,
阅读全文