codeforces 208(div2) A+B+C+D
2014-04-17 23:26
363 查看
链接:http://codeforces.com/contest/358
A:
题意:给n个数,按顺序的从第一个到最后,从当前点到下一个点,就在两点之间画一个弧,问按照顺序画的话,会不会出现有交叉的情况,有则输出yes否则no
思路:把每一个弧都存下来,判断当前的弧和之前所有的弧有没有交叉,O(n^2)的算法。
注意:弧存的时候注意数字大小,判断弧的时候分情况就行了。
B:
题意:主角要给女朋友发信息,但是要加密的。加密方案是在每个单词前都有‘<3’,最后一个单词之后还有一个'<3',他想要发的短信是加完'<3'之后的一个串。
现在再给你一个串,判断这个串里是不是完全包含上面那个加密后的串,如果包含yes否则no。
做法:构造好加密好的串,一位一位的比较就可以了。
C:
题意:主角要听从女朋友的命令,女朋友有两种命令,一种是非0,一个是0.有三个container:queue,stack,deck,如果是非0的命令,就要求主角把这个数字加入一种容器里,如果是0的命令,就要求从容器中取出一个数,然后清空三个容器。要求从容器里取出的数的和是最大的(因为取出数的和是女朋友亲他的数目)。
做法:如果两个0命令之间的非0数字不大于3,就可以把三个容器一个一个的加进去,然后pop掉。
如果大于三,就要先找出最大的三个,分别加到三个容器的front,剩下的加到deck的back。找最大的三个,我是用优先队列找的。
D:
题意:主角女朋友要喂排成一列的兔子,兔子被喂到时有三种happy值,一种是它旁边的两个兔子都没被喂,一种是之前有一个被喂过,一种是左右两个之前都被喂到了。
思路:
A:
题意:给n个数,按顺序的从第一个到最后,从当前点到下一个点,就在两点之间画一个弧,问按照顺序画的话,会不会出现有交叉的情况,有则输出yes否则no
思路:把每一个弧都存下来,判断当前的弧和之前所有的弧有没有交叉,O(n^2)的算法。
注意:弧存的时候注意数字大小,判断弧的时候分情况就行了。
#include<cstdio> #include<algorithm> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<queue> #include<vector> using namespace std; int n; int a[1005]; struct node{ int l,r; }s[1005]; int ind = 0; int main(){ cin>>n; for (int i = 0; i < n; i++) { cin>>a[i]; } if(n <= 2)puts("no"); else{ int flag = 0; int ff = 1; int l = a[0],r = a[1]; if(l > r){ff = 2;} s[ind].l = min(l,r);s[ind++].r = max(l,r); for (int i = 2; i < n && flag == 0; i++) { if(a[i] < r)ff = 2; else ff = 1; l = r,r = a[i]; for (int j = 0; j < ind; j++) { if(ff == 1){ if(r > s[j].r && l < s[j].r && l > s[j].l)flag=1; else if(l < s[j].l&&r>s[j].l&&r<s[j].r) flag = 1; }else{ if(l > s[j].r && r < s[j].r && r > s[j].l)flag=1; else if(r < s[j].l&&l>s[j].l&&l<s[j].r) flag = 1; } if(flag)break; } s[ind].l = min(l,r);s[ind++].r = max(l,r); } if(flag)puts("yes"); else puts("no"); } //system("pause"); return 0; }
B:
题意:主角要给女朋友发信息,但是要加密的。加密方案是在每个单词前都有‘<3’,最后一个单词之后还有一个'<3',他想要发的短信是加完'<3'之后的一个串。
现在再给你一个串,判断这个串里是不是完全包含上面那个加密后的串,如果包含yes否则no。
做法:构造好加密好的串,一位一位的比较就可以了。
#include<cstdio> #include<algorithm> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<queue> #include<vector> using namespace std; int n; char a[1000006],b[1000006],s[100005]; int main(){ int l = 0; cin>>n; a[l++] = '<';a[l++] = '3'; for (int i = 0; i < n; i++) { scanf("%s",s); for (int j = 0; s[j] ; j++) { a[l++] = s[j]; } a[l++] = '<';a[l++] = '3'; } scanf("%s",b); int len = strlen(b); int k = 0; for (int i = 0; i < len; i++) { if(b[i] == a[k])k++; } puts(k == l?"yes":"no"); return 0; }
C:
题意:主角要听从女朋友的命令,女朋友有两种命令,一种是非0,一个是0.有三个container:queue,stack,deck,如果是非0的命令,就要求主角把这个数字加入一种容器里,如果是0的命令,就要求从容器中取出一个数,然后清空三个容器。要求从容器里取出的数的和是最大的(因为取出数的和是女朋友亲他的数目)。
做法:如果两个0命令之间的非0数字不大于3,就可以把三个容器一个一个的加进去,然后pop掉。
如果大于三,就要先找出最大的三个,分别加到三个容器的front,剩下的加到deck的back。找最大的三个,我是用优先队列找的。
#include<cstdio> #include<algorithm> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<stack> #include<functional> using namespace std; #define maxn 3005 int a[100005]; struct node{ int l,n; }b[100005]; priority_queue<int> Q; int main(){ int n,ind; while(cin>>n){ ind = 0; for (int i = 0; i < n; i++)cin>>a[i]; int num = 0,l = 0; if(a[0] == 0)b[ind++].n = 0,l = 1; else num++; for (int i = 1; i < n; i++) { if(a[i] == 0)b[ind].l=l,b[ind++].n = num,num = 0,l = i+1; else num++; } int ff = 0; while(!Q.empty())Q.pop(); int x,y,z; for (int i = 0; i < ind; i++) { if(b[i].n == 0){puts("0");continue;} else if(b[i].n == 1){ puts("pushStack"); printf("1 popStack\n"); }else if(b[i].n == 2){ puts("pushStack");puts("pushQueue"); printf("2 popStack popQueue\n"); }else{ while(!Q.empty()){Q.pop();} for (int j = 0; j < b[i].n; j++)Q.push(a[b[i].l+j]); ff = 0; while(ff < 3){ for (int j = 0; j < b[i].n; j++) { if(ff == 0){ if(Q.top() == a[b[i].l + j]){ Q.pop();x = j; ff++; continue; } }else if(ff == 1){ if(Q.top() == a[b[i].l + j]){ Q.pop();y = j; ff++; continue; } }else if(ff == 2){ if(Q.top() == a[b[i].l + j]){ Q.pop();z = j; ff++; break; } } } } for (int j = 0; j < b[i].n; j++) { if(j == x){ puts("pushStack"); }else if(j == y){ puts("pushQueue"); }else if(j == z){ puts("pushFront"); }else puts("pushBack"); } printf("3 popStack popQueue popFront\n"); } } if(num){ for (int i = 0; i < num; i++) { puts("pushStack"); } } } return 0; }
D:
题意:主角女朋友要喂排成一列的兔子,兔子被喂到时有三种happy值,一种是它旁边的两个兔子都没被喂,一种是之前有一个被喂过,一种是左右两个之前都被喂到了。
思路:
/* So when I am at a particular hare I should know if I have fed the previous hare and I have to make a decision for the current one that whether it should be fed now or after the next hare So state would be like ( int position, bool previous ) if previous is true (previous hare is already fed) : 1. I can feed the current hare now so result1= solve( position+1, 1)+ b[position] 2. I will feed after the next one so result2 = solve( position+1, 0)+ c[position] Else if previous is false (previous hare is not fed) 1. I can feed the current hare now so result1= solve( position+1, 1)+ a[position] 2. I will feed after the next one so result2 = solve( position+1, 0)+ b[position] return max(result1,result2) */
#include<cstdio> #include<algorithm> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<queue> #include<vector> using namespace std; #define maxn 3005 int n; int a[maxn],b[maxn],c[maxn],dp[maxn][2]; int main(){ while(cin>>n){ for (int i = 0; i < n; i++)cin>>a[i]; for (int i = 0; i < n; i++)cin>>b[i]; for (int i = 0; i < n; i++)cin>>c[i]; memset(dp,0,sizeof(dp)); dp[n-1][0] = a[n-1];dp[n-1][1] = b[n-1]; for (int i = n-2; i >= 0; i--) { dp[i][0] = max(a[i]+dp[i+1][1],b[i]+dp[i+1][0]); dp[i][1] = max(b[i]+dp[i+1][1],c[i]+dp[i+1][0]); } cout<<dp[0][0]<<endl; } return 0; }
相关文章推荐
- Codeforces 208 div2 D. Dima and Hares
- [CodeForces]Round #Pi (Div. 2) Aug/05/2015
- Codeforces 441 (Div.1) 解题报告
- CodeForces-540C//Codeforces Round #301 (Div. 2)C BFS
- codeforces 428(div2) A-D
- codeforces 250 div2 A B C D
- codeforces 93 div2 D题 - kmp- 3
- Codeforces - 337C(div2) - Harmony Analysis
- Codeforces 208 B. Solitaire
- codeforces 183(div2) A. Pythagorean Theorem II 枚举+二分查找
- 【Codeforces Round #418 (Div. 2)】Codeforces 814E An unavoidable detour for home
- codeforces 97 div2 C.Replacement 水题
- 【Codeforces】Codeforces Round #271 div2
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
- 第十八次codeforces竞技结束 #272 Div 2
- Codeforces - AIM Tech Round (Div. 2)C - Graph and String
- [DP] Codeforces 403D #236 (Div. 1) D. Beautiful Pairs of Numbers
- AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)
- Codeforces-Round-#356-(Div.-2)-Bear-and-Five-Cards
- 【Codeforces Round #366 (Div. 2)】Codeforces 705B Spider Man