题目链接:http://codeforces.com/contest/975

A. Aramic script
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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?

Input

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

Output one integer — the number of different objects mentioned in the given ancient Aramic script.

Examples
Input

Copy
5
a aa aaa ab abb
Output

Copy
2
Input

Copy
3
amer arem mrea
Output

Copy
1
Note

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所含的元素数。

代码实现如下:


 #include <bits/stdc++.h>
using namespace std; int n;
int a[];
string s[], ss[]; int main() {
cin >>n;
for(int i = ; i < n;i++) {
getchar();
cin >>s[i];
ss[i].clear();
memset(a, , sizeof(a));
int len = s[i].size();
for(int j = ; j < len; j++) {
int t = s[i][j] - 'a';
a[t]++;
}
for(int j = ; j < ; j++) {
if(a[j]) ss[i] += (j + 'a');
}
}
set<string> m;
for(int i = ; i < n; i++) {
if(!m.count(ss[i])) {
m.insert(ss[i]);
}
}
cout <<m.size() <<endl;
return ;
}


B. Mancala
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Input

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

Output one integer, the maximum possible score after one move.

Examples
Input

Copy
0 1 1 0 0 0 0 0 0 7 0 0 0 0
Output

Copy
4
Input

Copy
5 1 1 1 1 0 0 0 0 0 0 0 0 0
Output

Copy
8
Note

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导致心态爆炸了……

代码实现如下:


 #include <bits/stdc++.h>
using namespace std; long long a[], b[]; int main() {
for(int i = ; i <= ; i++) {
cin >> a[i];
}
long long ans = , sum;
for(int i = ; i <= ; i++) {
sum = ;
memset(b, , sizeof(b));
if(a[i] <= )
continue;
for(int j = ; j <= ; j++) {
if(i != j) {
b[j] = a[j];
}
}
int n = a[i] / , m = a[i] % ;
for(int j = ; j <= ; j++) b[j] += n;
for(int j = i + ; j <= && m > ; j++, m--) {
b[j] ++;
}
for(int j = ; m > ; j++, m--) {
b[j] ++;
}
for(int j = ; j <= ; j++) {
if(b[j] % == ) {
sum += b[j];
}
}
ans = max(ans, sum);
}
cout << ans << endl;
return ;
}


C. Valhalla Siege
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Input

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

Output qq lines, the ii -th of them is the number of standing warriors after the ii -th minute.

Examples
Input

Copy
5 5
1 2 1 2 1
3 10 1 1 1
Output

Copy
3
5
4
4
3
Input

Copy
4 4
1 2 3 4
9 1 10 6
Output

Copy
1
4
4
1
Note

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,然后进行二分即可。

代码实现如下:

 #include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + ;
int n, q;
long long x;
long long a[maxn], sum[maxn]; int main() {
cin >>n >>q;
sum[] = ;
for(int i= ; i<=n;i++) {
cin >>a[i];
sum[i] = sum[i-] + a[i];
}
long long t = ;
while(q--) {
cin >>x;
t += x;
if(t >= sum[n]) t = ;
int pos = upper_bound(sum,sum + n + , t) - sum - ;
//cout <<pos <<endl <<endl;
cout <<n - pos <<endl;
}
return ;
}
D. Ghosts
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.

There are nn ghosts in the universe, they move in the OXYOXY plane, each one of them has its own velocity that does not change in time: →V=Vx→i+Vy→jV→=Vxi→+Vyj→ where VxVx is its speed on the xx-axis and VyVy is on the yy-axis.

A ghost ii has experience value EXiEXi, which represent how many ghosts tried to scare him in his past. Two ghosts scare each other if they were in the same cartesian point at a moment of time.

As the ghosts move with constant speed, after some moment of time there will be no further scaring (what a relief!) and the experience of ghost kind GX=∑ni=1EXiGX=∑i=1nEXi will never increase.

Tameem is a red giant, he took a picture of the cartesian plane at a certain moment of time TT, and magically all the ghosts were aligned on a line of the form y=a⋅x+by=a⋅x+b. You have to compute what will be the experience index of the ghost kind GXGX in the indefinite future, this is your task for today.

Note that when Tameem took the picture, GXGX may already be greater than 00, because many ghosts may have scared one another at any moment between [−∞,T][−∞,T].

Input

The first line contains three integers nn, aa and bb (1≤n≤2000001≤n≤200000, 1≤|a|≤1091≤|a|≤109, 0≤|b|≤1090≤|b|≤109) — the number of ghosts in the universe and the parameters of the straight line.

Each of the next nn lines contains three integers xixi, VxiVxi, VyiVyi (−109≤xi≤109−109≤xi≤109, −109≤Vxi,Vyi≤109−109≤Vxi,Vyi≤109), where xixi is the current xx-coordinate of the ii-th ghost (and yi=a⋅xi+byi=a⋅xi+b).

It is guaranteed that no two ghosts share the same initial position, in other words, it is guaranteed that for all (i,j)(i,j) xi≠xjxi≠xj for i≠ji≠j.

Output

Output one line: experience index of the ghost kind GXGX in the indefinite future.

Examples
Input

Copy
4 1 1
1 -1 -1
2 1 1
3 1 1
4 -1 -1
Output

Copy
8
Input

Copy
3 1 0
-1 1 0
0 0 -1
1 -1 -2
Output

Copy
6
Input

Copy
3 1 0
0 0 0
1 0 0
2 0 0
Output

Copy
0
Note

There are four collisions (1,2,T−0.5)(1,2,T−0.5), (1,3,T−1)(1,3,T−1), (2,4,T+1)(2,4,T+1), (3,4,T+0.5)(3,4,T+0.5), where (u,v,t)(u,v,t) means a collision happened between ghosts uu and vv at moment tt. At each collision, each ghost gained one experience point, this means that GX=4⋅2=8GX=4⋅2=8.

In the second test, all points will collide when t=T+1t=T+1.

The red arrow represents the 1-st ghost velocity, orange represents the 2-nd ghost velocity, and blue represents the 3-rd ghost velocity.

题意:n只鬼当在同一时刻同一坐标遇见时会被对方吓到,问在时间为负无穷到正无穷范围(一开始没读清楚,到比赛结束第二题晚上才读清楚,可能是因为比赛结束后补D已经到一点头脑不清醒的缘故吧)内所有鬼被吓到次数的和。神奇的是,在T时刻,所有的鬼都在直线y=ax+b上,给你鬼在T时刻的横坐标和鬼的在xy轴的速度。

思路:本题求的其实就是鬼的行进路线所在直线间的交点数*2,易知两条直线在同一平面内只有平行和相交,由题意所说的T时刻所有的鬼在同一直线上知,鬼的行进路线如果平行只能是同时沿着T时刻的那条直线运动;而不平行的肯定会相交啦~我们先将题目中给的信息进行化简,如下图(字丑见谅):

因此我们只要统计每个a*vx - vy(p)出现的次数即可,而对于在同一个a*vx-y的鬼(数量记为q,借助map进行储存,这个我是看了别人的代码才知道的==!),由于T时刻的x不同,因此,他们是不会相遇的。最后我们只要把每个鬼对应的p和q相减的值加起来即可。
代码实现如下:

 #include <map>
#include <cstdio>
#include <cstdlib>
using namespace std; const int maxn = 2e5 + ;
typedef long long ll;
int n, a, b;
ll x[maxn], y[maxn];
map<ll,ll> mp1;
map<pair<ll, ll>, ll> mp2; int main() {
scanf("%d%d%d", &n, &a, &b);
for(int i = ; i < n; i++) {
scanf("%*s%I64d%I64d", &x[i], &y[i]);
mp1[a * x[i] - y[i]]++;
mp2[make_pair(x[i], y[i])]++;
}
ll ans = ;
for(int i = ; i < n; i++) {
ans += mp1[a * x[i] - y[i]] - mp2[make_pair(x[i], y[i])];
}
printf("%I64d\n", ans);
return ;
}

Codeforces Round #478 (Div. 2)的更多相关文章

  1. 【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D

    传送门 题意:给你一条直线的斜率a和截距b,和某一时刻n个在直线上的点的横坐标,以及沿坐标轴方向的速度.问你这些点在(-∞,+∞)的时间内的碰撞次数. solution 设两个点在t时刻相碰,有: x ...

  2. 【推导】Codeforces Round #478 (Div. 2) D. Ghosts

    题意:给你一条直线以及初始时刻这条直线上的一些人的坐标,以及他们的速度矢量.让你对每个人计算他在过去无限远到将来无限远的时间内会与多少人处于同一个点,然后对每个人的这个值求和. 列方程组:两个人i,j ...

  3. Codeforces Round #478 (Div. 2) ABCDE

    A. Aramic script time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. B. Mancala (Codeforces Round #478 (Div. 2))

    #include <bits/stdc++.h> using namespace std; ; typedef long long ll; ll a[maxn]; ll b[maxn]; ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. ACM 第十一天

    多校7题目 GuGuFishtion Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  2. 3dContactPointAnnotationTool开发日志(二一)

      今天完成了修改按钮颜色,添加smpl模型到工具,以及可以显示物体子物体对应选项卡的功能.把之前的meshRenderer+meshFilter都改成了skinnedMeshRenderer,因为s ...

  3. 个人作业4 alpha阶段 个人总结

    一.个人总结 二.回答问题 三.再提问题 Q1:关于第三章过早优化 过早优化:既然软件是"软"的,那么它就有很大的可塑性,可以不断改进.放眼望去,一个复杂的软件似乎很多的模块都可以 ...

  4. 在线api查询网站

    1.包含各种常用的语言 http://tool.oschina.net/apidocs

  5. URL中编码问题

    1.http协议传输统一iso-8859-1传输 jsp中用request.getparameter("keword");得到的是iso-8859-1翻译过来的,要用 keywor ...

  6. html/css/javascript知识点集锦;完全小白开搞web编程

    知识点集锦 1.在html模板的代码中会有下面一类: {% block title %} Blog entries {% endblock %}这里的 block 和 endblock 是神马? {% ...

  7. bpf程序

    bpf都是怎么起作用的? 记得bpf之前是绑定在bpf bpf作用在哪里呀?

  8. [剑指Offer] 53.表示数值的字符串

    题目描述 请实现一个函数用来判断字符串是否表示数值(包括整数和小数).例如,字符串"+100","5e2","-123","3.1 ...

  9. DELPHI的MEMO组件

    位于Standard选项卡上,它是对EDIT控件的扩展,可以对多行文本进行显示.输入 和编辑. Lines属性: 该属性实际上为TStrings类型的对象,用来存放Memo对象的文本 TStrings ...

  10. 【Python】Python SQLAlchemy基本操作和常用技巧

    首先说下,由于最新的 0.8 版还是开发版本,因此我使用的是 0.79 版,API 也许会有些不同.因为我是搭配 MySQL InnoDB 使用,所以使用其他数据库的也不能完全照搬本文. 接着就从安装 ...