Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
- Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Print the decoded number.
3
111
3
9
110011101
2031
这是个划水题,就是题目意思不大清楚,其实就是一个长度为n的字符串,遇到0作为一个进位
#include <bits/stdc++.h> using namespace std;int main() { int n; cin>>n; string s; cin>>s; int t=1; for(int i=1;i<n;i++) if(s[i]=='0'&&s[i-1]!='0'){ cout<<t;t=0;} else if(s[i]=='1') t++; else if(s[i]=='0') cout<<"0"; cout<<t; return 0; }
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.
Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.
You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O'being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed that in the current arrangement nobody has still won.
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........
YES
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........
NO
B就是暴力,你有一盘五子棋,X是你的棋,O是对手的题,然后你可以改变一个.实现赢棋
所以我就每次都往右,左下,下,右下这四个方向走,遇到O肯定是GG,遇到墙也GG,只有cnt=3才是符合题要求的,但是这个墙也许也行,这个才是最GG的
这个是分析自己的棋的,比较爆炸。还是分析空位比较好
#include <bits/stdc++.h> using namespace std; char s[12][12]; int dfs(int x,int y) { int cnt=0; for(int i=1; i<5; i++) { if(x+i>10||s[x+i][y]=='O') { if(cnt==3&&i==4&&s[x-1][y]=='.') return 1; else cnt=0; break; } else if(s[x+i][y]=='X') cnt++; } if(cnt==3) return 1; cnt=0; for(int i=1; i<5; i++) { if(x+i>10||y+i>10||s[x+i][y+i]=='O') { if(cnt==3&&i==4&&s[x-1][y-1]=='.') return 1; else cnt=0; break; } else if(s[x+i][y+i]=='X') cnt++; } if(cnt==3) return 1; cnt=0; for(int i=1; i<5; i++) { if(x+i>10||y-i<1||s[x+i][y-i]=='O') { if(cnt==3&&i==4&&s[x-1][y+1]=='.') return 1; else cnt=0; break; } else if(s[x+i][y-i]=='X') cnt++; } if(cnt==3) return 1; cnt=0; for(int i=1; i<5; i++) { if(y+i>10||s[x][y+i]=='O') { if(cnt==3&&i==4&&s[x][y-1]=='.') return 1; else cnt=0; break; } else if(s[x][y+i]=='X') cnt++; } if(cnt==3) return 1; return 0; } int main() { memset(s,'O',sizeof(s)); for(int i=1; i<11; i++) cin>>s[i]+1; for(int i=1; i<11; i++) for(int j=1; j<11; j++) { if(s[i][j]=='X') { if(dfs(i,j)){ return 0*printf("YES\n");} } } return 0*printf("NO\n");; }
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).
Makes has chosen n problems to solve on Decoforces with difficulties a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty (no matter on what online judge was it).
Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.
With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.
For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.
Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.
Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
3 3
2 1 9
1
4 20
10 3 6 3
0
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second example he can solve every problem right from the start.
C的意思Codeforces上有n个问题,要解决难度为a[i]的,必须解决难度为d>=a[i]/2(在任何OJ上都行),求最少在其他OJ上完成多少道题
所以用贪心啊,先做简单的,那么这个难度d也会最小,你做的就会更多了
来看下AA聚聚的代码,短到不行,另外这个auto原来还有这种奇功啊,还有这vector一个数组,比push_back要省内存,能达到数组的使用效果,而且使用起来更方便,强无敌
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (auto& x : a) { cin >> x; } sort(a.begin(), a.end()); int ans = 0; for (auto x : a) { while (k * 2 < x) { ans++; k *= 2; } k = max(k, x); } cout << ans << endl; return 0; }
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters.
Suitability of string s is calculated by following metric:
Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings s, you choose the one with the largest number of non-intersecting occurrences of string t. Suitability is this number of occurrences.
You should replace all '?' characters with small Latin letters in such a way that the suitability of string s is maximal.
The first line contains string s (1 ≤ |s| ≤ 106).
The second line contains string t (1 ≤ |t| ≤ 106).
Print string s with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.
If there are multiple strings with maximal suitability then print any of them.
?aa?
ab
baab
??b?
za
azbz
abcd
abacaba
abcd
In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2.
In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.
In the third example there are no '?' characters and the suitability of the string is 0.
D也是贪心,实现下题目操作就好
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; vector<int> a(255),b; for (int i = 0; i < (int)s.size(); i++) { char c = s[i]; if (c != '?') { a[c]++; } else { b.push_back(i); } } while (!b.empty()) { for (auto c : t) { if (a[c] > 0) a[c]--; else { s[b.back()] = c; b.pop_back(); if (b.empty()) break; } } } cout << s << endl; return 0; }