zoukankan      html  css  js  c++  java
  • Codeforces Round #478 (Div. 2) ABCDE

    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.
    • 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?

    Input

    The first line contains one integer nn (1n1031≤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".



    题意:对于每个字符串,他的根是他所有不同字符组成的字符串组成的任意排列,其中所有都排列代表的都是同一个根。然后让你对所有字符串输出不同的根的个数。题解:对于一个字符串的根我们可以用一个最大为$ 2^{27} -1 $ 的数表示,那我们每次检查这个数在之前是否出现过。没有则标记该数并答案+1。
     1 #include<bits/stdc++.h>
     2 #define clr(x) memset(x,0,sizeof(x))
     3 #define mod 1000000007
     4 #define clr_1(x) memset(x,-1,sizeof(x))
     5 #define INF 0x3f3f3f3f
     6 #define LL long long
     7 #define pb push_back
     8 #define pbk pop_back
     9 using namespace std;
    10 const int N=1e3+10;
    11 const int type=26;
    12 int pt[N];
    13 bool num[type];
    14 int n,m,k,nub,p,i;
    15 char s[N];
    16 int main()
    17 {
    18     int n;
    19     scanf("%d",&n);
    20     k=0;
    21     for(int t=1;t<=n;t++)
    22     {
    23         scanf("%s",s);
    24         clr(num);
    25         nub=0;
    26         for(i=0;s[i];i++)
    27         {
    28             p=s[i]-'a';
    29             if(!num[p])
    30                 nub^=(1<<p),num[p]=1;
    31         }
    32         for(i=1;i<=k;i++)
    33         {
    34             if(nub==pt[i])
    35                 break;
    36         }
    37         if(i>k)
    38             pt[++k]=nub;
    39     }
    40     printf("%d
    ",k);
    41     return 0;
    42 }
    View Code
    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 (0ai1090≤ai≤109) — the number of stones in each hole.

    It is guaranteed that for any ii (1i141≤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个洞,每个洞里有一定数量的石头。然后现在让你选择一个洞里有石头的洞i,把里面石头都取出来,然后按照$ i,i+1,i+2……14,1,2……14,1,2…… $不断循环地一个一个放石头。最后放完后吧偶数颗石头的洞里的石头都取出来。问这样操作一次最多获得多少石头。题解:按照题意模拟一下取14个洞每个洞的情况取最大值。
     1 #include<bits/stdc++.h>
     2 #define clr(x) memset(x,0,sizeof(x))
     3 #define mod 1000000007
     4 #define clr_1(x) memset(x,-1,sizeof(x))
     5 #define INF 0x3f3f3f3f
     6 #define LL long long
     7 #define pb push_back
     8 #define pbk pop_back
     9 using namespace std;
    10 const int N=20;
    11 const int type=26;
    12 LL p[N],evey[N];
    13 LL ans,maxn,allo,t;
    14 int n,m;
    15 int main()
    16 {
    17     for(int i=0;i<14;i++)
    18         scanf("%I64d",p+i);
    19     maxn=0;
    20     for(int i=0;i<14;i++)
    21     if(p[i])
    22     {
    23         allo=p[i];
    24         for(int j=0;j<14;j++)
    25             if(i!=j)
    26                 evey[j]=p[j];
    27             else
    28                 evey[j]=0;
    29         t=allo%14;
    30         for(int j=i+1;j<t+i+1;j++)
    31             evey[j%14]++;
    32         t=allo/14;
    33         for(int j=0;j<14;j++)
    34             evey[j]+=t;
    35         ans=0;
    36         for(int j=0;j<14;j++)
    37             if(evey[j]%2==0)
    38                 ans+=evey[j];
    39         maxn=max(ans,maxn);
    40     }
    41     printf("%I64d
    ",maxn);
    42     return 0;
    43 }
    View Code
    C. Valhalla Siege
    time limit per test
    2 seconds
    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 (i1)(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 (1n,q2000001≤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 (1ai1091≤ai≤109) that represent the warriors' strengths.

    The third line contains qq integers k1,k2,,kqk1,k2,…,kq (1ki10141≤ki≤1014), the ii-th of them represents Lagertha's order at the ii-th minute: kikiarrows 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.

    题意:有n个士兵,每个士兵都有一定的承受伤害值,表示他能承受几根箭的攻击。然后有q轮攻击,每轮攻击会发射$ k_i $根箭,若有士兵存活则一定命中最左侧存活士兵。当在某一轮中所有士兵全中箭死亡时,在这轮末尾也就是箭全部发射完毕时所有士兵都会复活。问每轮攻击后也就是轮末有多少士兵存活。题解:维护一个士兵承受伤害的前缀和,每次二分(lower_bound)查找总承受攻击p下最左侧士兵。当总承受攻击p大于等于最右也就是n的前缀和时,p清零并存活人数为n。
     1 #include<bits/stdc++.h>
     2 #define clr(x) memset(x,0,sizeof(x))
     3 #define mod 1000000007
     4 #define clr_1(x) memset(x,-1,sizeof(x))
     5 #define INF 0x3f3f3f3f
     6 #define LL long long
     7 #define pb push_back
     8 #define pbk pop_back
     9 #define itn int 
    10 #define mian main
    11 using namespace std;
    12 const int N=2e5+10;
    13 const int type=26;
    14 int n,m,q,pos;
    15 LL so[N],pre[N];
    16 LL now,att;
    17 int main()
    18 {
    19     scanf("%d%d",&n,&q);
    20     for(int i=1;i<=n;i++)
    21         scanf("%I64d",so+i);
    22     pre[0]=0;
    23     now=0;
    24     for(int i=1;i<=n;i++)
    25         pre[i]=pre[i-1]+so[i];
    26     for(int i=1;i<=q;i++)
    27     {
    28         scanf("%I64d",&att);
    29         now+=att;
    30         if(now>=pre[n])
    31         {
    32             printf("%d
    ",n);
    33             now=0;
    34         }
    35         else
    36         {
    37             pos=upper_bound(pre+1,pre+n+1,now)-pre;
    38             printf("%d
    ",n-pos+1);
    39         }
    40     }
    41     return 0;
    42 }
    View Code
    D. Ghosts
    time limit per test
    2 seconds
    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=Vxi+VyjV→=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=ax+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 (1n2000001≤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 (109xi109−109≤xi≤109, 109Vxi,Vyi109−109≤Vxi,Vyi≤109), where xixi is the current xx-coordinate of the ii-th ghost (and yi=axi+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) xixjxi≠xj for iji≠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


    
    
    题意:就是有一些鬼,他们都有各自的横向速度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} $
    即:
    $x_i+t v_{ix} = x_j +v_{jx} $

    $ a x_i+t v_{iy} = a x_j +v_{jy} $
    上下两式相减可得:
    $ a v_{ix} - v_{iy} = a v_{jy} - v_{jy} $
    那么我们只有$ a v_{ix} - v_{iy} $相同的点才可能相遇。
    因此我们要统计上式的值得点数。
    但满足上式,其速度v一样的点是不可能相遇的。
    因此我们在统计完上式值以后还要统计不同v下的点数。
    然后对于每个相同的上式值,不同v的点对答案的贡献则是速度为v的点乘上速度不为v的点的个数。
    因此写个map<LL,map<LL,LL> >是坠好的。
     1 #include<bits/stdc++.h>
     2 #define clr(x) memset(x,0,sizeof(x))
     3 #define mod 1000000007
     4 #define clr_1(x) memset(x,-1,sizeof(x))
     5 #define INF 0x3f3f3f3f
     6 #define LL long long
     7 #define pb push_back
     8 #define pbk pop_back
     9 using namespace std;
    10 const int N=2e5+10;
    11 map<LL,LL> ct;
    12 map<LL,map<LL,LL> > num;
    13 int n;
    14 LL k,b,x,vx,vy;
    15 LL ans;
    16 int main()
    17 {
    18     scanf("%d%I64d%I64d",&n,&k,&b);
    19     ct.clear();
    20     for(int i=1;i<=n;i++)
    21     {
    22         scanf("%I64d%I64d%I64d",&x,&vx,&vy);
    23         ct[k*vx-vy]++;
    24         num[k*vx-vy][vx]++;
    25     }
    26     ans=0;
    27     for( auto t:num)
    28     {
    29         x=t.first;
    30         for(auto pt:t.second)
    31         {
    32             ans+=pt.second*(ct[x]-pt.second);
    33         }
    34     }
    35     printf("%I64d
    ",ans);
    36     return 0;
    37 }
    View Code
    E. Hag's Khashba
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    • 1ftt: 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.
    • 2vv: 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.

    Input

    The first line contains two integers nn and qq (3n100003≤n≤10000, 1q2000001≤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 (1f,tn1≤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 (1vn1≤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.

    Output

    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 10410−4.

    Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if |ab|max(1,|b|)104|a−b|max(1,|b|)≤10−4

    Examples
    input
    Copy
    3 4
    0 0
    2 0
    2 2
    1 1 2
    2 1
    2 2
    2 3
    output
    Copy
    3.4142135624 -1.4142135624
    2.0000000000 0.0000000000
    0.5857864376 -1.4142135624
    input
    Copy
    3 2
    -1 1
    0 0
    1 1
    1 1 2
    2 1
    output
    Copy
    1.0000000000 -1.0000000000
    Note

    In the first test note the initial and the final state of the wooden polygon.


    题意:给定一个多边形木板(质量均匀)的所有顶点在墙上初始坐标,并把这个多边形用两个钉子钉在墙上。初始钉子在顶点1和2的位置。然后有执行q个操作,每个操作是如下一种:1是把其中一个在顶点u的钉子拔起来,等木板自然下落稳定后把钉子按在顶点v处。2是询问当前某个顶点u的坐标。

    题解:我的做法是在操作的时候保存当前两个钉子所在的顶点的真实坐标,以及他们对应哪个顶点。并保存当前和重心在一条垂线上的顶点是哪个。然后刚开始的时候预处理出多边形重心。接下来按照同垂线的顶点的真实坐标,来推重心的真实位置,并求出询问顶点的坐标和更新稳定后钉子所钉顶点的真实坐标。

    这题其实不卡精度,不写_float128也行。

      1 #include<bits/stdc++.h>
      2 #define clr(x) memset(x,0,sizeof(x))
      3 #define mod 1000000007
      4 #define clr_1(x) memset(x,-1,sizeof(x))
      5 #define INF 0x3f3f3f3f
      6 #define LL long long
      7 #define pb push_back
      8 #define pbk pop_back
      9 #define __float128 double
     10 using namespace std;
     11 const int N=2e5+10;
     12  struct point
     13 {
     14     __float128 x,y;
     15     point() {x=0;y=0;}
     16     point operator + (point b)
     17     {
     18         b.x=b.x+x;
     19         b.y=b.y+y;
     20         return b;
     21     }
     22     point operator - (point b)
     23     {
     24         b.x=x-b.x;
     25         b.y=y-b.y;
     26         return b;
     27     }
     28     point operator * (point b)
     29     {
     30         b.x=x*b.x;
     31         b.y=y*b.y;
     32         return b;
     33     }
     34     point operator * (__float128 b)
     35     {
     36         point pt;
     37         pt.x=x*b;
     38         pt.y=y*b;
     39         return pt;
     40     }
     41     __float128 dot(point b)//点积
     42     {
     43         return x*b.x+y*b.y;
     44     }
     45     __float128 det(point b)//叉积
     46     {
     47         return x*b.y-y*b.x;
     48     }
     49     point operator / (__float128 t)
     50     {
     51         point pt;
     52         pt.x=x/t;
     53         pt.y=y/t;
     54         return pt;
     55     }
     56     __float128 mo()
     57     {
     58         return x*x+y*y;
     59     }
     60 };
     61 int now;
     62 int p[2];
     63 point pos[N],z,zb[2],vecon,zx,tp,ans,t,cx[N];
     64 int n,q,dd,u,v;
     65 double x,y;
     66 __float128 s[N],sall;
     67 bool flag;
     68 int op;
     69 int main()
     70 {
     71     scanf("%d%d",&n,&q);
     72     for(int i=0;i<n;i++)
     73     {
     74         scanf("%lf%lf",&x,&y);
     75         pos[i].x=(__float128)x;
     76         pos[i].y=(__float128)y;
     77     }
     78     z.x=0;
     79     z.y=0;
     80     sall=0;
     81     for(int i=1;i<n-1;i++)
     82     {
     83         cx[i]=(pos[0]+pos[i]+pos[i+1])/3;
     84         s[i]=(pos[i]-pos[0]).det(pos[i+1]-pos[0]);
     85             z=z*(sall/(sall+s[i]))+cx[i]*(s[i]/(sall+s[i]));
     86         sall+=s[i];
     87     }
     88     zb[0]=pos[0];
     89     zb[1]=pos[1];
     90     p[0]=0;
     91     p[1]=1;
     92     now=0;
     93     flag=0;
     94     for(int i=1;i<=q;i++)
     95     {
     96         scanf("%d",&op);
     97         if(op==2)
     98         {
     99             scanf("%d",&dd);
    100             dd--;
    101             if(!flag)
    102                 printf("%.13f %.13f
    ",(double)pos[dd].x,(double)pos[dd].y);
    103             else
    104             {
    105                 t=pos[p[now]]-z;
    106                 tp=pos[dd]-z;
    107                 vecon.x=0;
    108                 vecon.y=sqrtl(t.mo());
    109                 zx=zb[now]-vecon;
    110                 ans.x=zx.x*vecon.mo()+tp.x*t.dot(vecon)-tp.y*t.det(vecon);
    111                 ans.x/=vecon.mo();
    112                 ans.y=zx.y*vecon.mo()+tp.x*t.det(vecon)+tp.y*t.dot(vecon);
    113                 ans.y/=vecon.mo();
    114                 printf("%.13f %.13f
    ",(double)ans.x,(double)ans.y);
    115             }
    116         }
    117         else
    118         {
    119             flag=1;
    120             scanf("%d%d",&u,&v);
    121             u--;
    122             v--;
    123             for(int j=0;j<2;j++)
    124                 if(p[j]==u)
    125                 {
    126                     now=j^1;
    127                     p[j]=v;
    128                     break;
    129                 }
    130                 t=pos[p[now]]-z;
    131                 tp=pos[p[now^1]]-z;
    132                 vecon.x=0;
    133                 vecon.y=sqrtl(t.mo());
    134                 zx=zb[now]-vecon;
    135                 zb[now^1].x=zx.x*vecon.mo()+tp.x*t.dot(vecon)-tp.y*t.det(vecon);
    136                 zb[now^1].x/=vecon.mo();
    137                 zb[now^1].y=zx.y*vecon.mo()+tp.x*t.det(vecon)+tp.y*t.dot(vecon);
    138                 zb[now^1].y/=vecon.mo();
    139         }
    140     }
    141     return 0;
    142 }
    View Code
  • 相关阅读:
    客户端session与服务端session
    对session和cookie的一些理解
    Servlet生命周期与工作原理
    Linux命令行编辑快捷键
    含有GROUP BY子句的查询中如何显示COUNT()为0的成果(分享)
    设计模式学习——准备(UML类图)
    find()方法
    js中的动态效果
    动态添加,移除,查找css属性的方法
    VUE中的require ( )
  • 原文地址:https://www.cnblogs.com/wujiechao/p/8978726.html
Copyright © 2011-2022 走看看