摘要: 题目:http://soj.me/1021 很好的启蒙题 n对夫妇站成一个圈将相邻的夫妇取出 若全部夫妇均能取出 输出Yes 否则输出No思路:将夫妇从编号1到2n的夫妇分别压入栈,如果栈顶的夫妇和即将压入的夫妇相同,则退栈。若最后全部夫妇退栈 输出Yes 其中用了一个arr[a] = b;arr[b] = a;的方法来记录夫妇的状态 还不会用c++的stack,就用数组模拟了一个#include <iostream>#include <string>#include <algorithm>using namespace std;int arr[200000 阅读全文
posted @ 2013-01-23 23:25 Daniel Qiu 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 题目:http://soj.me/1052这题暴露出我的英文水平...读题读错两次...首先 题目说simultaneously 结果我以为一个个轮流分糖果 齐次 拿到糖果后如果是奇数就找老师要 而不是分糖果之前如果是奇数找老师要这题还挺麻烦的 要开个二维数组 或者两个一维数组 一个记录从旁边那里拿了多少个 一个数组记录自己还剩多少个#include <iostream>#include <string>#include <algorithm>using namespace std;int arr[100000][2];int main(){ while(1 阅读全文
posted @ 2013-01-23 21:11 Daniel Qiu 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 题目:http://soj.me/1057思路:这题求的是贝尔数http://zh.wikipedia.org/wiki/%E8%B4%9D%E5%B0%94%E6%95%B0用以下方法建构一个三角矩阵(形式类似杨辉三角形):第一行第一项是1(a_{1,1} = 1)对于n>1,第n行第一项等同第n-1行最后一项。()对于m,n>1,第n行第m项等于它左边和左上方的两个数之和。()然后因为上限是50 输出的数超大 所以用数组存不想开三位数组,就用string写了个高精度的加法;#include <iostream>#include <string>#incl 阅读全文
posted @ 2013-01-23 19:21 Daniel Qiu 阅读(326) 评论(0) 推荐(0) 编辑
摘要: 题目:http://soj.me/1007这题主要练习一下c++里面对string的操作#include <iostream>#include <string>#include <cstring>#include <algorithm>using namespace std; string temp;string str[100];int main(){ while(1) { int n; cin>>n; if(n==0) break; int c=0; cin>>temp; int col=n; ... 阅读全文
posted @ 2013-01-23 15:27 Daniel Qiu 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 题目:http://soj.me/1001一串数字问一共有多少种编码的可能性思路:code[i]为题目给出的数字(i从零开始)当i>=2时如果code[i]=0 case1:ans[i]=ans[i-2](因为code[i-1]不能单独存在 必须与code[i]合并,如3120,ans[1]=1,ans[2]=2,ans[3]=1)如果code[i]!=0 如果code[i-1]=0 case2:ans[i]=ans[i-1](code[i]必须单独存在,如3102,ans[1]=1,ans[2]=1,ans[3]=1) 如果code[i-1]!=0 如果code[i-1]与... 阅读全文
posted @ 2013-01-23 13:49 Daniel Qiu 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 题目:http://codeforces.com/contest/231/problem/A思路:模拟法#include <iostream>using namespace std;int main(){ int n; cin>>n; int ans=0; for (int i = 0; i < n; i++) { int a,b,c; cin>>a>>b>>c; if(a+b+c>=2) ans++; } cout << ans; return 0;} 阅读全文
posted @ 2013-01-23 12:23 Daniel Qiu 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 题目:http://codeforces.com/contest/233/problem/A输出ppi = i且pi ≠ i的数列思路:pi=x px=i#include <iostream>using namespace std;int main(){ int n; cin>>n; if(n%2!=0) cout <<"-1"; else { for(int i=0;i<n;i++) { cout<<n-i<<" "; } } return 0;} 阅读全文
posted @ 2013-01-23 12:14 Daniel Qiu 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 题目:http://www.codeforces.com/contest/266/problem/B思路:模拟法#include <iostream>using namespace std;char arr[55];int main(){ int n,t; cin >> n >> t; for (int i = 0; i < n; i++) { cin >> arr[i]; } for(int i=0;i<t;i++) { for (int j = 0; j < n; j++) { if(... 阅读全文
posted @ 2013-01-23 11:42 Daniel Qiu 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 题目:http://www.codeforces.com/contest/266/my思路:模拟法#include <iostream>using namespace std;char arr[55];int main(){ int n; cin>>n; for(int i=0;i<n;i++) { cin>>arr[i]; } int ans=0; for(int i=0;i<n;i++) { if(arr[i]==arr[i+1]) ans++; } cout << ans; ... 阅读全文
posted @ 2013-01-23 11:41 Daniel Qiu 阅读(119) 评论(0) 推荐(0) 编辑