Codeforces Round #478 (Div. 2) ABCDE
1 second
256 megabytes
standard input
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, theroot 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".
题意:对于每个字符串,他的根是他所有不同字符组成的字符串组成的任意排列,其中所有都排列代表的都是同一个根。然后让你对所有字符串输出不同的根的个数。题解:对于一个字符串的根我们可以用一个最大为$ 2^{27} -1 $ 的数表示,那我们每次检查这个数在之前是否出现过。没有则标记该数并答案+1。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
using namespace std;
const int N=1e3+;
const int type=;
int pt[N];
bool num[type];
int n,m,k,nub,p,i;
char s[N];
int main()
{
int n;
scanf("%d",&n);
k=;
for(int t=;t<=n;t++)
{
scanf("%s",s);
clr(num);
nub=;
for(i=;s[i];i++)
{
p=s[i]-'a';
if(!num[p])
nub^=(<<p),num[p]=;
}
for(i=;i<=k;i++)
{
if(nub==pt[i])
break;
}
if(i>k)
pt[++k]=nub;
}
printf("%d\n",k);
return ;
}
1 second
256 megabytes
standard input
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.
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个洞,每个洞里有一定数量的石头。然后现在让你选择一个洞里有石头的洞i,把里面石头都取出来,然后按照$ i,i+1,i+2……14,1,2……14,1,2…… $不断循环地一个一个放石头。最后放完后吧偶数颗石头的洞里的石头都取出来。问这样操作一次最多获得多少石头。题解:按照题意模拟一下取14个洞每个洞的情况取最大值。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
using namespace std;
const int N=;
const int type=;
LL p[N],evey[N];
LL ans,maxn,allo,t;
int n,m;
int main()
{
for(int i=;i<;i++)
scanf("%I64d",p+i);
maxn=;
for(int i=;i<;i++)
if(p[i])
{
allo=p[i];
for(int j=;j<;j++)
if(i!=j)
evey[j]=p[j];
else
evey[j]=;
t=allo%;
for(int j=i+;j<t+i+;j++)
evey[j%]++;
t=allo/;
for(int j=;j<;j++)
evey[j]+=t;
ans=;
for(int j=;j<;j++)
if(evey[j]%==)
ans+=evey[j];
maxn=max(ans,maxn);
}
printf("%I64d\n",maxn);
return ;
}
2 seconds
256 megabytes
standard input
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.
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: kikiarrows 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.
题意:有n个士兵,每个士兵都有一定的承受伤害值,表示他能承受几根箭的攻击。然后有q轮攻击,每轮攻击会发射$ k_i $根箭,若有士兵存活则一定命中最左侧存活士兵。当在某一轮中所有士兵全中箭死亡时,在这轮末尾也就是箭全部发射完毕时所有士兵都会复活。问每轮攻击后也就是轮末有多少士兵存活。题解:维护一个士兵承受伤害的前缀和,每次二分(lower_bound)查找总承受攻击p下最左侧士兵。当总承受攻击p大于等于最右也就是n的前缀和时,p清零并存活人数为n。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
#define itn int
#define mian main
using namespace std;
const int N=2e5+;
const int type=;
int n,m,q,pos;
LL so[N],pre[N];
LL now,att;
int main()
{
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++)
scanf("%I64d",so+i);
pre[]=;
now=;
for(int i=;i<=n;i++)
pre[i]=pre[i-]+so[i];
for(int i=;i<=q;i++)
{
scanf("%I64d",&att);
now+=att;
if(now>=pre[n])
{
printf("%d\n",n);
now=;
}
else
{
pos=upper_bound(pre+,pre+n+,now)-pre;
printf("%d\n",n-pos+);
}
}
return ;
}
2 seconds
256 megabytes
standard input
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].
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 one line: experience index of the ghost kind GXGX in the indefinite future.
4 1 1
1 -1 -1
2 1 1
3 1 1
4 -1 -1
8
3 1 0
-1 1 0
0 0 -1
1 -1 -2
6
3 1 0
0 0 0
1 0 0
2 0 0
0
题意:就是有一些鬼,他们都有各自的横向速度vx和纵向速度vy,他们会一直按照这个速度走。然后在题目给出的时刻,他们全部在y=ax+b这条直线上,并给出每个鬼所处的x。然后问这些鬼每一个和其他鬼相遇的次数,并求相遇次数的总和。
题解:你可以列一个方程,其中$ x_i ,y_i $ 代表 i 在直线y=ax+b的x坐标、y坐标,$ v_{ix},v_{iy} $分别代表i的横向速度和纵向速度。对于另一个鬼j也类似。那么我们可以列出方程组:
$ x_i+t v_{ix} = x_j +v_{jx} $
$ y_i+t v_{iy} = y_j +v_{jy} $
$ a x_i+t v_{iy} = a x_j +v_{jy} $
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
using namespace std;
const int N=2e5+;
map<LL,LL> ct;
map<LL,map<LL,LL> > num;
int n;
LL k,b,x,vx,vy;
LL ans;
int main()
{
scanf("%d%I64d%I64d",&n,&k,&b);
ct.clear();
for(int i=;i<=n;i++)
{
scanf("%I64d%I64d%I64d",&x,&vx,&vy);
ct[k*vx-vy]++;
num[k*vx-vy][vx]++;
}
ans=;
for( auto t:num)
{
x=t.first;
for(auto pt:t.second)
{
ans+=pt.second*(ct[x]-pt.second);
}
}
printf("%I64d\n",ans);
return ;
}
3 seconds
256 megabytes
standard input
standard output
Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering.
Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and other boring subjects. He confronted Hag with the fact that he is a spoiled son that does not care about his future, and if he continues to do arts he will cut his 25 Lira monthly allowance.
Hag is trying to prove to his dad that the wooden piece is a project for mechanics subject. He also told his dad that the wooden piece is astrictly convex polygon with nn vertices.
Hag brought two pins and pinned the polygon with them in the 11-st and 22-nd vertices to the wall. His dad has qq queries to Hag of two types.
- 11 ff tt: pull a pin from the vertex ff, wait for the wooden polygon to rotate under the gravity force (if it will rotate) and stabilize. And then put the pin in vertex tt.
- 22 vv: answer what are the coordinates of the vertex vv.
Please help Hag to answer his father's queries.
You can assume that the wood that forms the polygon has uniform density and the polygon has a positive thickness, same in all points. After every query of the 1-st type Hag's dad tries to move the polygon a bit and watches it stabilize again.
The first line contains two integers nn and qq (3≤n≤100003≤n≤10000, 1≤q≤2000001≤q≤200000) — the number of vertices in the polygon and the number of queries.
The next nn lines describe the wooden polygon, the ii-th line contains two integers xixi and yiyi (|xi|,|yi|≤108|xi|,|yi|≤108) — the coordinates of the ii-th vertex of the polygon. It is guaranteed that polygon is strictly convex and the vertices are given in the counter-clockwise order and all vertices are distinct.
The next qq lines describe the queries, one per line. Each query starts with its type 11 or 22. Each query of the first type continues with two integers ff and tt (1≤f,t≤n1≤f,t≤n) — the vertex the pin is taken from, and the vertex the pin is put to and the polygon finishes rotating. It is guaranteed that the vertex ff contains a pin. Each query of the second type continues with a single integer vv (1≤v≤n1≤v≤n) — the vertex the coordinates of which Hag should tell his father.
It is guaranteed that there is at least one query of the second type.
The output should contain the answer to each query of second type — two numbers in a separate line. Your answer is considered correct, if its absolute or relative error does not exceed 10−410−4.
Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if |a−b|max(1,|b|)≤10−4|a−b|max(1,|b|)≤10−4
3 4
0 0
2 0
2 2
1 1 2
2 1
2 2
2 3
3.4142135624 -1.4142135624
2.0000000000 0.0000000000
0.5857864376 -1.4142135624
3 2
-1 1
0 0
1 1
1 1 2
2 1
1.0000000000 -1.0000000000
In the first test note the initial and the final state of the wooden polygon.
题意:给定一个多边形木板(质量均匀)的所有顶点在墙上初始坐标,并把这个多边形用两个钉子钉在墙上。初始钉子在顶点1和2的位置。然后有执行q个操作,每个操作是如下一种:1是把其中一个在顶点u的钉子拔起来,等木板自然下落稳定后把钉子按在顶点v处。2是询问当前某个顶点u的坐标。
题解:我的做法是在操作的时候保存当前两个钉子所在的顶点的真实坐标,以及他们对应哪个顶点。并保存当前和重心在一条垂线上的顶点是哪个。然后刚开始的时候预处理出多边形重心。接下来按照同垂线的顶点的真实坐标,来推重心的真实位置,并求出询问顶点的坐标和更新稳定后钉子所钉顶点的真实坐标。
这题其实不卡精度,不写_float128也行。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
#define __float128 double
using namespace std;
const int N=2e5+;
struct point
{
__float128 x,y;
point() {x=;y=;}
point operator + (point b)
{
b.x=b.x+x;
b.y=b.y+y;
return b;
}
point operator - (point b)
{
b.x=x-b.x;
b.y=y-b.y;
return b;
}
point operator * (point b)
{
b.x=x*b.x;
b.y=y*b.y;
return b;
}
point operator * (__float128 b)
{
point pt;
pt.x=x*b;
pt.y=y*b;
return pt;
}
__float128 dot(point b)//点积
{
return x*b.x+y*b.y;
}
__float128 det(point b)//叉积
{
return x*b.y-y*b.x;
}
point operator / (__float128 t)
{
point pt;
pt.x=x/t;
pt.y=y/t;
return pt;
}
__float128 mo()
{
return x*x+y*y;
}
};
int now;
int p[];
point pos[N],z,zb[],vecon,zx,tp,ans,t,cx[N];
int n,q,dd,u,v;
double x,y;
__float128 s[N],sall;
bool flag;
int op;
int main()
{
scanf("%d%d",&n,&q);
for(int i=;i<n;i++)
{
scanf("%lf%lf",&x,&y);
pos[i].x=(__float128)x;
pos[i].y=(__float128)y;
}
z.x=;
z.y=;
sall=;
for(int i=;i<n-;i++)
{
cx[i]=(pos[]+pos[i]+pos[i+])/;
s[i]=(pos[i]-pos[]).det(pos[i+]-pos[]);
z=z*(sall/(sall+s[i]))+cx[i]*(s[i]/(sall+s[i]));
sall+=s[i];
}
zb[]=pos[];
zb[]=pos[];
p[]=;
p[]=;
now=;
flag=;
for(int i=;i<=q;i++)
{
scanf("%d",&op);
if(op==)
{
scanf("%d",&dd);
dd--;
if(!flag)
printf("%.13f %.13f\n",(double)pos[dd].x,(double)pos[dd].y);
else
{
t=pos[p[now]]-z;
tp=pos[dd]-z;
vecon.x=;
vecon.y=sqrtl(t.mo());
zx=zb[now]-vecon;
ans.x=zx.x*vecon.mo()+tp.x*t.dot(vecon)-tp.y*t.det(vecon);
ans.x/=vecon.mo();
ans.y=zx.y*vecon.mo()+tp.x*t.det(vecon)+tp.y*t.dot(vecon);
ans.y/=vecon.mo();
printf("%.13f %.13f\n",(double)ans.x,(double)ans.y);
}
}
else
{
flag=;
scanf("%d%d",&u,&v);
u--;
v--;
for(int j=;j<;j++)
if(p[j]==u)
{
now=j^;
p[j]=v;
break;
}
t=pos[p[now]]-z;
tp=pos[p[now^]]-z;
vecon.x=;
vecon.y=sqrtl(t.mo());
zx=zb[now]-vecon;
zb[now^].x=zx.x*vecon.mo()+tp.x*t.dot(vecon)-tp.y*t.det(vecon);
zb[now^].x/=vecon.mo();
zb[now^].y=zx.y*vecon.mo()+tp.x*t.det(vecon)+tp.y*t.dot(vecon);
zb[now^].y/=vecon.mo();
}
}
return ;
}
Codeforces Round #478 (Div. 2) ABCDE的更多相关文章
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #460 (Div. 2) ABCDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...
- Codeforces Round #546 (Div. 2) ABCDE 题解
1136A: 题意:一本书有n个章节,每个章节的分别在li到ri页,小明读完书后将书折在第k页,问还有多少章节没有读 题解:控制k在li~ri的范围内后输出n-i即可 #include <set ...
- Codeforces Round #478 (Div. 2)
题目链接:http://codeforces.com/contest/975 A. Aramic script time limit per test:1 second memory limit pe ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- Codeforces Round #375 (Div. 2) ABCDE
A - The New Year: Meeting Friends 水 #include<iostream> #include<algorithm> using namespa ...
- Codeforces Round #105 (Div. 2) ABCDE
A. Insomnia cure 哎 只能说英语太差,一眼题我看了三分钟. 题意:给5个数k, l, m, n 和 d,求1~d中能被k, l, m, n 至少一个整除的数的个数. 题解:…… 代码: ...
- Codeforces Round #306 (Div. 2) ABCDE(构造)
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
随机推荐
- HTTP/2.0 简单总结(转载)
HTTP/2.0 简单总结(转载于https://linjunzhu.github.io/blog/2016/03/10/http2-zongjie/) 如何使用上 HTTP/2.0 需要浏览器的支持 ...
- localStorage H5本地存储
域内安全.永久保存.即客户端或浏览器中来自同一域名的所有页面都可访问localStorage数据且数据除了删除否则永久保存,但客户端或浏览器之间的数据相互独立. <!doctype html&g ...
- Java多线程学习(七)并发编程中一些问题
本节思维导图: 关注微信公众号:"Java面试通关手册" 回复"Java多线程"获取思维导图源文件和思维导图软件. 多线程就一定好吗?快吗?? 并发编程的目的就 ...
- scandir函数的研究【笔记】
以下是本人的学习笔记,代码并非原创,均摘自官方源码,贴出来仅供学习记录用 scandir 的使用要注意内存泄漏的问题 scandir函数实现: vi ./uClibc-0.9.33.2/libc/mi ...
- pycharm双击无响应,打不开问题解决办法
之前好好的pycharm,突然双击打不开了,怎么办? 亲测有效方案: 第一步:进入如下路径,找到cmd.exe,右键选择“以管理员身份运行”: 第二步:在打开的cmd窗口中,输入 netsh wins ...
- nginx升级至1.12.1版本
nginx升级至1.12.1 编号 名称 说明 1 nginx-1.12.1.tar.gz nginx安装程序 2 nginx_upstream_check_module-master.zip 实现后 ...
- C# 获取mp3文件的歌曲时间长度
添加命名空间: using Shell32; using System.Text.RegularExpressions;添加引用:COM组件的Microsoft Shell Control ...
- 无状态Http
无状态的根本原因 浏览器和服务器使用socket通信,服务器将请求结果返回给浏览器后,会关闭当前socket连接.而且服务器会在处理页面完毕后销毁页面对象. 应用层面的原因 浏览器和服务器之间通信都遵 ...
- oracle只要第一条数据SQL
select * from ( select * from COMMON_BIZREL_WF where sponsor is not null order by serialid ) where r ...
- WebService初识
Web service 是一种跨编程语言和跨操作系统平台的远程调用技术,即跨平台远程调用技术.也就是说,不管是J2EE架构,还是.net架构 只要按照规范就可以进行通信,实现数据交互等. 这里说的&q ...