题目链接:http://codeforces.com/contest/975
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once.
- A root and all its permutations represent the same object.
- The root xx of a word yy is the word that contains all letters that appear in yy in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab".
- Any word in Aramic represents the same object as its root.
You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
The first line contains one integer nn (1≤n≤1031≤n≤103) — the number of words in the script.
The second line contains nn words s1,s2,…,sns1,s2,…,sn — the script itself. The length of each string does not exceed 103103.
It is guaranteed that all characters of the strings are small latin letters.
Output one integer — the number of different objects mentioned in the given ancient Aramic script.
5
a aa aaa ab abb
2
3
amer arem mrea
1
In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
题意:给你n个字符串,然后把每个字符串中出现的字母取出来(构成的新字符串忽略顺序记为根),问这n个字符串中不同根的个数。
思路:用一个数组a记录每个字符串中出现的字母,然后再把它按照字典序构成一个新的字符串用set来维护,结果就是set所含的元素数。
代码实现如下:
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n; 5 int a[26]; 6 string s[1007], ss[1007]; 7 8 int main() { 9 cin >>n; 10 for(int i = 0; i < n;i++) { 11 getchar(); 12 cin >>s[i]; 13 ss[i].clear(); 14 memset(a, 0, sizeof(a)); 15 int len = s[i].size(); 16 for(int j = 0; j < len; j++) { 17 int t = s[i][j] - 'a'; 18 a[t]++; 19 } 20 for(int j = 0; j < 26; j++) { 21 if(a[j]) ss[i] += (j + 'a'); 22 } 23 } 24 set<string> m; 25 for(int i = 0; i < n; i++) { 26 if(!m.count(ss[i])) { 27 m.insert(ss[i]); 28 } 29 } 30 cout <<m.size() <<endl; 31 return 0; 32 }
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has aiai stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.
Note that the counter-clockwise order means if the player takes the stones from hole ii, he will put one stone in the (i+1)(i+1)-th hole, then in the (i+2)(i+2)-th, etc. If he puts a stone in the 1414-th hole, the next one will be put in the first hole.
After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.
Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.
The only line contains 14 integers a1,a2,…,a14a1,a2,…,a14 (0≤ai≤1090≤ai≤109) — the number of stones in each hole.
It is guaranteed that for any ii (1≤i≤141≤i≤14) aiai is either zero or odd, and there is at least one stone in the board.
Output one integer, the maximum possible score after one move.
0 1 1 0 0 0 0 0 0 7 0 0 0 0
4
5 1 1 1 1 0 0 0 0 0 0 0 0 0
8
In the first test case the board after the move from the hole with 77 stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to 44.
题意:给你14个洞,每个洞里面有0个或奇数个石子,然后可以进行一次操作,这题操作就是将一个含非零石子数的洞中的石子全部取出然后按顺序填入后面的洞中(超出14就从第一个洞开始),每次只能放1个。
思路:因为总共就14个洞,所以就暴力即可(坑点:会爆int)~比赛时因为某个地方爆了int没发现和突然zz导致心态爆炸了……
代码实现如下:
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 long long a[20], b[20]; 5 6 int main() { 7 for(int i = 1; i <= 14; i++) { 8 cin >> a[i]; 9 } 10 long long ans = 0, sum; 11 for(int i = 1; i <= 14; i++) { 12 sum = 0; 13 memset(b, 0, sizeof(b)); 14 if(a[i] <= 0) 15 continue; 16 for(int j = 1; j <= 14; j++) { 17 if(i != j) { 18 b[j] = a[j]; 19 } 20 } 21 int n = a[i] / 14, m = a[i] % 14; 22 for(int j = 1; j <= 14; j++) b[j] += n; 23 for(int j = i + 1; j <= 14 && m > 0; j++, m--) { 24 b[j] ++; 25 } 26 for(int j = 1; m > 0; j++, m--) { 27 b[j] ++; 28 } 29 for(int j = 1; j <= 14; j++) { 30 if(b[j] % 2 == 0) { 31 sum += b[j]; 32 } 33 } 34 ans = max(ans, sum); 35 } 36 cout << ans << endl; 37 return 0; 38 }
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has nn warriors, he places them on a straight line in front of the main gate, in a way that the ii -th warrior stands right after (i−1)(i−1) -th warrior. The first warrior leads the attack.
Each attacker can take up to aiai arrows before he falls to the ground, where aiai is the ii -th warrior's strength.
Lagertha orders her warriors to shoot kiki arrows during the ii -th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute tt , they will all be standing to fight at the end of minute tt .
The battle will last for qq minutes, after each minute you should tell Ivar what is the number of his standing warriors.
The first line contains two integers nn and qq (1≤n,q≤2000001≤n,q≤200000 ) — the number of warriors and the number of minutes in the battle.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109 ) that represent the warriors' strengths.
The third line contains qq integers k1,k2,…,kqk1,k2,…,kq (1≤ki≤10141≤ki≤1014 ), the ii -th of them represents Lagertha's order at the ii -th minute: kiki arrows will attack the warriors.
Output qq lines, the ii -th of them is the number of standing warriors after the ii -th minute.
5 5
1 2 1 2 1
3 10 1 1 1
3
5
4
4
3
4 4
1 2 3 4
9 1 10 6
1
4
4
1
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die.
- after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive.
- after the 3-rd minute, the 1-st warrior dies.
- after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1.
- after the 5-th minute, the 2-nd warrior dies.
题意:人肉盾请了解一下,第i个人可以抵挡ai只弓箭(看作hp),第i分钟地方射出ki只箭, 战争持续了q分钟。问每分钟还有多少人还活着(注意,当所有人都死亡时,将会集体复活,雾)。
思路:用前缀和记录前i个人的总hp,然后用t来记录前i分钟的弓箭数,当t>=sum[n]时将t设为0,然后进行二分即可。
代码实现如下:
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 2e5 + 7; 5 int n, q; 6 long long x; 7 long long a[maxn], sum[maxn]; 8 9 int main() { 10 cin >>n >>q; 11 sum[0] = 0; 12 for(int i= 1; i<=n;i++) { 13 cin >>a[i]; 14 sum[i] = sum[i-1] + a[i]; 15 } 16 long long t = 0; 17 while(q--) { 18 cin >>x; 19 t += x; 20 if(t >= sum[n]) t = 0; 21 int pos = upper_bound(sum,sum + n + 1, t) - sum - 1; 22 //cout <<pos <<endl <<endl; 23 cout <<n - pos <<endl; 24 } 25 return 0; 26 }