codeforce #129
来源:互联网 发布:黎明杀机mac能不能玩 编辑:程序博客网 时间:2024/04/28 13:23
A
Description
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input
The first line contains the only integer n (1 ≤ n ≤ 100) — the number of cookie bags Anna and Maria have. The second line containsn integers ai (1 ≤ ai ≤ 100) — the number of cookies in thei-th bag.
Output
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
通过观察可以发现,当a[0] + ..a[n-1] 为奇数时,答案为a[i]是偶数的个数,和为偶数时,是a[i]
奇数的个数
/*********************************************** * Author: fisty * Created Time: 2015/6/15 20:53:31 * File Name : F.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int, int> P;#define FOR(i, a, b) for(int i = a;i < b; i++)int main() { //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; int sum = 0; int odd = 0; int even = 0; int x; FOR(i, 0, n){ cin >> x; if(x % 2) odd++; else even++; sum += x; } if(sum % 2) cout << odd << endl; else cout << even << endl; return 0;}
C. - Statues
Description
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Sample Input
.......A................................................M.......
WIN
搜索是否可以从M到达A, 并且在走的同时有雕塑下落,为可否到达。顺便记录走的时间,如果时间大于8,说明所有雕塑都到达底部,M一定可以到达A,则跳出
/*********************************************** * Author: fisty * Created Time: 2015/6/16 21:10:32 * File Name : D.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int, int> P;#define FOR(i, a, b) for(int i = a;i < b; i++)#define MAX_N 10char G[MAX_N][MAX_N];int vis[MAX_N][MAX_N][MAX_N];struct node{ int x, y, d; node(int x, int y, int d):x(x), y(y), d(d){}};void bfs(){ Memset(vis, 0); queue<node> que; que.push(node(7, 0, 0)); while(que.size()){ node q = que.front(); que.pop(); if(q.d >= 8){ cout << "WIN" << endl; return ; } if(G[q.x - q.d][q.y] == 'S') continue; for(int i = -1; i <= 1; i++){ for(int j = -1;j <= 1; j++){ int x = q.x + i, y = q.y + j; if(G[x - q.d][y] != 'S' && x >= 0 && y >= 0 && x < 8 && y < 8){ if(!vis[x][y][q.d+1]){ que.push(node(x, y, q.d+1)); vis[x][y][q.d+1] = 1; } } } } } puts("LOSE");}int main() { //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); FOR(i, 0, 8){ FOR(j, 0, 8){ cin >> G[i][j]; } } bfs(); return 0;}
D StringTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
One day in the IT lesson Anna and Maria learned about the lexicographic order.
String x is lexicographically less than stringy, if either x is a prefix ofy (and x ≠ y), or there exists suchi (1 ≤ i ≤ min(|x|, |y|)), thatxi < yi, and for anyj (1 ≤ j < i)xj = yj. Here|a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages.
The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only thek-th string from the list. Help Anna and Maria do the homework.
Input
The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed105. The second line contains the only integerk (1 ≤ k ≤ 105).
Output
Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less thank, print a string saying "No such line." (without the quotes).
用优先队列模拟求出字符串中第k大的子串
/*********************************************** * Author: fisty * Created Time: 2015/6/16 19:59:55 * File Name : C.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int, int> P;#define FOR(i, a, b) for(int i = a;i < b; i++)#define MAX_N 100100int k;string s;struct node{ string s; int d; node(string s = " ", int d = 0) : s(s), d(d){} bool operator<(const node &q)const{ return s > q.s; }};priority_queue <node> que;int main() { //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); cin >> s; cin >> k; int n = s.size(); node t; for(int i = 0;i < n; i++){ t.s = s[i]; t.d = i; que.push(t); } int ok = 0; while(!que.empty()){ node p = que.top(); que.pop(); //cout << p.s << endl; k--; if(k == 0){ cout << p.s << endl; ok = 1; break; } p.d++; if(p.d < s.size()){ p.s = p.s + s[p.d]; que.push(p); } } if(!ok) cout << "No such line." << endl; return 0;}
- codeforce #129
- codeforce
- codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- CodeForce
- Codeforce 1
- codeforce 规则
- codeforce Domino
- codeforce 224
- 关于Codeforce
- update语句的语法与原理
- Android程序:使用ViewPager实现app引导页效果
- 图像检索:Bag-of-words模型简介
- Android ADB server didn't ACK * failed to start daemon * 简单有效的解决方案
- python最简单的爬取邮箱地址
- codeforce #129
- js输出一个字符串中出现次数最多的字符
- QTP中DataTable类型参数化步骤举例
- smart_stl::deque相关总结
- docker 常用命令
- Bag of Features (BOF)图像检索算法
- 理解Javascript_09_Function与Object
- 今天更新sdk,遇到了更新下载失败问题:
- Intents and Intent Filters