01 2013 档案
摘要:题目:http://poj.org/problem?id=1008 玛雅人历法的一道题。 不愧是POJ,看上去的一道水题都能这么恶心...这题WA了好多次 最早是漏了uayet 这个月份 然后是一年的最后一天当成了下一年 下面这组数据: 输入:4. uayet 259 输出:13 ahau 364 只要过了这组数据就没问题了...#include <iostream>#include <string>#include <stdio.h>#include <cstdlib>using namespace std;string hname[19]={
阅读全文
摘要:题目:http://poj.org/problem?id=1007 根据逆序数排序#include <iostream>#include <string>#include <stdio.h>#include <cstdlib>using namespace std;struct DNA{ string str; int rank;}dna[105];int cmp(const void *a,const void *b){ return ((struct DNA *)a)->rank-((struct DNA *)b)->rank;}
阅读全文
摘要:题目:http://poj.org/problem?id=1006思路:中国剩余定理#include <iostream>#include <stdio.h>using namespace std;int main(){ int p,e,i,d; int c=1; while(1) { cin>>p>>e>>i>>d; if(p==-1) break; int n; n=(5544*p+14421*e+1288*i-d+21252)%(23*28*33); if(n==0) n=21252; ...
阅读全文
摘要:题目:http://poj.org/problem?id=1005水题#include <iostream>#include <stdio.h>#include <algorithm>#include <string>#include <string.h>#include <cstdlib>#include <cmath>using namespace std;const double PI=3.1415926;int main(){ int n; cin>>n; for(int i=1;i<
阅读全文
摘要:题目:http://poj.org/problem?id=1004水题#include <iostream>#include <stdio.h>#include <algorithm>#include <string>#include <string.h>#include <cstdlib>using namespace std;int main(){ float total=0; for(int i=0;i<12;i++) { float t; cin>>t; total+=t; } printf(&q
阅读全文
摘要:题目:http://poj.org/problem?id=1003 模拟题,比1002简单好多...#include <iostream>#include <stdio.h>#include <algorithm>#include <string>#include <string.h>#include <cstdlib>using namespace std;int main(){ while(1) { float len; cin>>len; if(len==0) break; float temp=0; .
阅读全文
摘要:题目:http://poj.org/problem?id=1002 模拟题 以前做了一半没做下去 现在重新做 WA了n次 cin读入效率不如scanf,cout输出000-0000会变成0-0,读入用的字符串开了20不够用 一怒之下开到200 结果AC了...#include <iostream>#include <stdio.h>#include <algorithm>#include <string>#include <string.h>#include <cstdlib>using namespace std;int
阅读全文
摘要:题目:http://poj.org/problem?id=1159 一个字符串至少添加几个字符才能构成回文字符串思路:其实和上一题很像 把字符串反过来求最长公共子序列 但是这题卡了空间... 于是在网上看到滚动数组...#include <iostream>#include <algorithm>#include <string>#include <string.h>using namespace std;int dp[5005];int pre[5005];int main(){ int len; string str; while(cin&g
阅读全文
摘要:题目:http://poj.org/problem?id=1458 最长公共子序列思路:DP#include <iostream>#include <string>#include <string.h>using namespace std;int dp[1000][1000];int main(){ string str1,str2; while(cin>>str1>>str2) { int len1,len2; len1=str1.size(); len2=str2.size(); memset(dp,0,siz...
阅读全文
摘要:题目:http://soj.me/1350 n个储蓄罐 储蓄罐的钥匙在储蓄罐内 已知钥匙所在的储蓄罐 求最少打破几个储蓄罐才能取出钱。思路:求图中环的个数由于图中每个点的出度只有1,所以不存在一个点处于两个环的交点因此,求环的个数时每个只需要考虑一次便可得出结果由于数据规模庞大,写成递归形式容易暴栈在读边的过程中先对自环进行预处理,之后对每个点进行不同的染色,对它的下一个点也染同样的颜色这样染下去如果发现下一个要染的点和正在染的颜色相同,则说明存在一个环换染色起点的同时也需要更换新的染色,才能保证对环的判断正确又一次栽在多case的初始化上...#include <iostream>
阅读全文
摘要:题目:http://soj.me/1155 n座城市 m条道路 问能否从第一座城市走到最后一座城市思路:广度优先搜索#include <iostream>#include <queue>#include <memory.h>using namespace std;bool map[205][205];bool visit[205];int n,m;bool bfs(){ queue<int> q; q.push(0); while(!q.empty()) { int temp=q.front(); q.pop(); ...
阅读全文
摘要:题目:http://codeforces.com/contest/268/problem/C思路:输出最大正方形副对角线的整数点坐标#include <iostream>using namespace std;int main(){ int x,y; cin>>x>>y; cout<<min(x,y)+1<<endl; for(int i=min(x,y);i>=0;i--) { cout <<i<<" "<<min(x,y)-i<<endl; } return
阅读全文
摘要:题目:http://codeforces.com/contest/268/problem/B#include <iostream>using namespace std;int main(){ int n; cin>>n; int ans=0; for(int i=1;i<n;i++) { ans+=i*(n-i); } ans+=n; cout<< ans;}
阅读全文
摘要:题目:http://codeforces.com/contest/268/problem/A#include <iostream>using namespace std;int arr[35][2];int main(){ int n; cin>>n; for(int i=0;i<n;i++) { cin>>arr[i][0]>>arr[i][1]; } int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(arr[i...
阅读全文
摘要:题目:http://soj.me/1931一叠编号为1~n的牌。当至少还剩两张牌时进行以下操作:把第一张牌扔掉,然后把新的第一张放到整叠牌的最后。输入n,输出每次扔掉的牌,以及最后剩下的牌。思路:简单队列操作 模拟法#include <iostream>#include <cstdlib>#include <queue>using namespace std;int arr[105];int main(){ int t; cin>>t; while(t--) { queue<int> q; int n; cin>>n; .
阅读全文
摘要:题目:http://soj.me/1443 根据priority决定打印的顺序,若priority不是最高,则排在队列最后面思路:基本队列操作 模拟法 #include <iostream>#include <cstdlib>#include <queue>using namespace std;int arr[105];int p[105];struct jobs{ int priority; bool target;}job[100];int cmp(const void *a,const void *b){ return *((int *)b)-*((
阅读全文
摘要:题目:http://soj.me/1200找出不能组成筷子的木棍思路:排序这题用了STL的sort()#include <iostream>#include <algorithm>using namespace std;int arr[105];int main(){ while (1) { int n; cin>>n; if(!n) break; for(int i=0;i<n;i++) { cin>>arr[i]; } sort(arr,arr+n); ...
阅读全文
摘要:题目: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
阅读全文
摘要:题目:http://soj.me/1052这题暴露出我的英文水平...读题读错两次...首先 题目说simultaneously 结果我以为一个个轮流分糖果 齐次 拿到糖果后如果是奇数就找老师要 而不是分糖果之前如果是奇数找老师要这题还挺麻烦的 要开个二维数组 或者两个一维数组 一个记录从旁边那里拿了多少个 一个数组记录自己还剩多少个#include <iostream>#include <string>#include <algorithm>using namespace std;int arr[100000][2];int main(){ while(1
阅读全文
摘要:题目: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
阅读全文
摘要:题目: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; ...
阅读全文
摘要:题目: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]与...
阅读全文
摘要:题目: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;}
阅读全文
摘要:题目: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;}
阅读全文
摘要:题目: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(...
阅读全文
摘要:题目: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; ...
阅读全文
摘要:题目:http://codeforces.com/contest/265/problem/C这题本来会做的 结果比赛的时候少打了个0..最后判定的时候runtime error了...#include <iostream>#include <stdio.h>#include <cstring>#include <cmath>using namespace std;char arr[1000005];int ans[1000005];int lp,rp;int main(){ cin.getline(arr,1000005); int len=st
阅读全文
摘要:题目:http://codeforces.com/contest/265/problem/B#include <iostream>#include <stdio.h>#include <cstring>#include <cmath>using namespace std;int arr[100000];int main(){ int n; cin>>n; for(int i=0;i<n;i++) { cin >> arr[i]; } int ans=2*n-1+arr[0]; for(int i=0;i<n-
阅读全文
摘要:题目:http://codeforces.com/contest/265/problem/A#include <iostream>#include <stdio.h>#include <cstring>using namespace std;char str[55];char ins[55];int main(){ cin.getline(str,55); cin.getline(ins,55); int slen=strlen(str); int ilen=strlen(ins); int i; for(i=0;i<slen;) { f...
阅读全文
摘要:题目:http://codeforces.com/contest/236/problem/A思路:模拟法#include <iostream>#include <cstring>using namespace std;int arr[26];int main(){ char str[100]; cin>>str; int charnum[100]; for(int i=0;i<26;i++) { arr[i]=0; } for(int i=0;i<strlen(str);i++) { charnum[i]=str[i]...
阅读全文
摘要:题目:http://codeforces.com/contest/237/problem/A#include <iostream>using namespace std;int main(){ int ans=1; int n; cin>>n; int ap,bp; int a,b; cin>>a>>b; ap=a; bp=b; int counter=1; for(int i=0;i<n-1;i++) { cin>>a>>b; if((a==ap)&&(b==bp)) { ...
阅读全文
摘要:题目:http://codeforces.com/contest/242/problem/A抛硬币 输出各种满足条件的结果#include <iostream>using namespace std;int arr[10000][2];int main(){ int x,y,a,b; cin>>x>>y>>a>>b; int n=0; for(int i=a;i<=x;i++) { for(int j=b;j<=y;j++) { if(i>j) { arr[n]...
阅读全文
摘要:题目:http://codeforces.com/contest/246/problem/A题目给出错误的冒泡排序法,求反例。思路:...既然是错误的,任意输出一个递减的数列#include <iostream>using namespace std;int main(){ int n; cin>>n; if(n<=2) cout<<"-1"; else { for(int i=0;i<n-2;i++) { cout<<n-i<<" "; } cout<<"2
阅读全文
摘要:题目:http://codeforces.com/contest/248/problem/An个橱柜 每个橱柜左右两扇门 用0、1纪录关和开的状态,问要使所有左门状态相同,右门状态相同,最少需要对门做几次操作思路:贪心法 分别统计左右门,输出关闭的状态和打开的状态中的较小值。#include <iostream>using namespace std;int l,r;int lopen=0,lclose=0,ropen=0,rclose=0;int main(){ int n; cin>>n; for(int i=0;i<n;i++) { cin >>
阅读全文
摘要:题目:http://codeforces.com/contest/250/problem/A将数列分割城若干个数列,每个子数列的负元素不得超过两个,使子数列个数最少,输出子数列个数,和每个子数列元素个数。思路:贪心法#include <iostream>using namespace std;int a[100];int b[100];int bi=0;int bn=1;int main(){ int n; cin>>n; for(int i=0;i<n;i++) { cin >> a[i]; } int neg=0; for(int i=0;i<
阅读全文
摘要:题目:http://www.codeforces.com/problemset/problem/252/A输出元素格个小于100的数列中连续子数列的异或最大值思路:个数小于100 直接枚举#include <iostream>#include <stdio.h>using namespace std;int arr[100];int ans=0;int main(){ int n; cin>>n; for(int i=0;i<n;i++) { cin>>arr[i]; } for(int i=0;i<n;i++) { int...
阅读全文
摘要:题目:http://codeforces.com/problemset/problem/253/A男女排队,男生多则男生站第一位vice versa#include <iostream>#include <stdio.h>using namespace std;int main(){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); int n,m; cin>>n>>m; if(n>
阅读全文
摘要:题目:http://codeforces.com/problemset/problem/255/B这题被ljc剧透了...#include <iostream>#include <stdio.h>#include <cmath>using namespace std;int main(){ char c; int xnum=0,ynum=0; while((c=cin.get())!=EOF) { if(c=='x') xnum++; else if(c=='y') ynum++; } int t=abs(xnum-ynum)
阅读全文
摘要:题目:http://codeforces.com/problemset/problem/254/A 给出n个数据,如果能分为2n对数据,每对数据相同 则输出这n对数据的标号 否则输出-1思路:这题一开始是暴力法...果然超时 然后看到1 ≤ ai ≤ 5000 于是开了一个a[5000]的数组 #include <iostream>#include <stdio.h>using namespace std;int a[5000];int pairs[1000000][2];int main(){ int counter=0; freopen("input.tx
阅读全文
摘要:题目:http://codeforces.com/contest/259/problem/B一个magic square满足每行每列每对角线的和相等给出一个除去主对角线(main diagonal)的square 求magic square思路:这题受input sample的影响,一开始傻逼了...以为每个数都小于10...然后就枚举了...然后发现数据的上限是105... 正解是 设每行每列每对角线的和为sum,magic square中所有数字加起来的和为3*sum; 所以剩下的数的和为2*sum#include <iostream>using namespace std;i
阅读全文
摘要:题目:http://codeforces.com/contest/257/problem/B思路:找规律...#include <iostream>using namespace std;int main(){ int n,m; int p,v; cin >> n >> m; if(n>m) { int t; t=n; n=m; m=t; } p=m-1; v=n; cout << p<<" "<<v; return 0;}
阅读全文
摘要:题目:http://codeforces.com/contest/263/problem/B在第一象限画n个以原点为顶点,(ai,ai)为对角顶点的正方形输出任意一个k为顶点的正方形思路:任意一个点,选正方形的顶点#include <iostream>#include <cstdlib>using namespace std;int arr[55];int cmp(const void *a,const void *b){ return *((int *)b)-*((int *)a);}int main(){ int n,k; cin>>n >>
阅读全文
摘要:题目:http://codeforces.com/contest/263/problem/A#include <iostream>#include <cmath>using namespace std;int main(){ int t; int row,col; for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { cin >>t; if(t==1) { row=i+1; co...
阅读全文
摘要:题目:http://codeforces.com/contest/262/problem/Bn个数按不递减的顺序排好k次取相反数思路:一边读入数据,一边做取反操作一开始忽略了有k>n且所有数为负数的情况,导致没有进行k次取反,只进行了n次。#include <iostream>#include <cstdlib>#include <cmath>using namespace std;int main(){ int n,k; long long sum=0; cin >> n >> k; int min=10005; bool o
阅读全文
摘要:题目:http://codeforces.com/contest/255/problem/A#include <iostream>#include <cstdlib>using namespace std;int main(){ int n; int arr[25]; int muscle[3]={0,0,0}; cin >> n; for(int i=0;i<n;i++) { int temp; cin >> temp; muscle[i%3]+=temp; } int maxi=0,max=muscl...
阅读全文
摘要:题目:http://codeforces.com/contest/259/problem/A判断一个棋盘经过行操作后能否成为一个正常的黑白相间的棋盘思路:因为不涉及列操作 只要每行都是黑白相间就可以满足条件#include <iostream>#include <cstdlib>using namespace std;int a,b,n;int main(){ bool ans=true; char start,previous,current; for(int i=0;i<8;i++) { cin >> current; start=pre...
阅读全文
摘要:题目:http://codeforces.com/contest/260/problem/A思路:a%b==0 => a*10^n%b==0这题一开始忽略了一句话If there are multiple possible answers, print any of them.想了半天觉得答案不只一种啊然后看到n的范围就知道这题不可能一位位算#include <iostream>#include <cstdlib>using namespace std;int a,b,n;int main(){ cin >> a>>b>>n;
阅读全文
摘要:题目:http://codeforces.com/contest/257/problem/A给出接线板 用电器 原有插座的数量;给出每个接线板的插座个数;求最少需要多少插线板;思路:贪心法#include <iostream>#include <cstdlib>using namespace std;int n,m,k;int arr[55];int cmp(const void *a,const void *b){ return *((int *)b)-*((int *)a);}int main(){ cin >> n >> m >>
阅读全文
摘要:题目:http://codeforces.com/contest/262/problem/A#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int main(){ int n,k; cin >> n >> k; int num; int ans=0; char digit[10]; for(int i=0;i<n;i++) { int counter=0; cin >> num; int flag=1; ...
阅读全文
摘要:题目:http://poj.org/problem?id=3030思路:模拟题#include <iostream>using namespace std;int main(){ int n; cin >> n; int r,e,c; for(int i=0;i<n;i++) { cin >> r >> e >> c; if(r<e-c) cout << "advertise" <<endl; else if(r==e-c) cout << "does no
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1843这题我做了有五个小时...就是没读懂题目中 "从每一个数字开始数一次" 是什么意思...思路:既然是循环我就构建了个循环链表,然后从M往上一个个枚举。#include <iostream>#include <cmath>#include <stdio.h>using namespace std;int digit[10];int num;struct nodes{ int n; nodes *next;}node[10];void create
阅读全文
摘要:题目:http://hustoj.sinaapp.com/problem.php?id=1838输入一个自然数N 请写一个程序来增序输出分母小于等于N的既约真分数思路:将分子分母和值存入结构体 根据值对结构体排序#include <iostream>#include <cstdlib>#include <cmath>using namespace std;struct fraction{ int numerator; int denominator; float value;}f[10000];int cmp(const void *a,const void
阅读全文
浙公网安备 33010602011771号