Codeforces Round #416
Posted Persistent.
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #416相关的知识,希望对你有一定的参考价值。
(?_?)最近脑子不好使(虽然一直都不太好用。。。)
A题换了三个思路,全wa了(ó﹏ò?),改了差不多15遍都有了(菜的醉死。。。)
最后让老大给我看看,哇,错了好多地方???????。
大佬给我改好了代码,我自己又开始改,我的小宇宙要爆发了,还好最后也改对了(菜的要撞墙了 |墙|????;));
At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Single line of input data contains two space-separated integers a, b (1?≤?a,?b?≤?109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
1 1
Valera
7 6
Vladik
Illustration for first test case:
Illustration for second test case:
题意就是两个人依次拿出多于上一个人的糖(我饿了。。。),不解释了,反正自己以后应该能看懂题意。
代码:(老大帮我改的)
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; int num1,num2; while(~scanf("%d%d",&n,&m)){ num1=0;num2=0; int t=n; for(int i=0;i<=t;i=i+2){ if(n>=i+1){ num1++; n=n-(i+1); } if(m>=i+2){ num2++; m=m-(2+i); } } //cout<<num1<<" "<<num2<<endl; if(num1<=num2) printf("Vladik\n"); else printf("Valera\n"); } return 0; }
代码:(我终于改对的)
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; int num1,num2; while(~scanf("%d%d",&n,&m)){ num1=0;num2=0; int t=n; for(int i=1;i<=t;i++){ //我的天呢,脑子离家出走了,我一开始写的i=0;i<=n,n会变的。〒▽〒 if(n>=2*i-1){ num1++; n-=2*i-1; } if(m>=2*i){ num2++; m-=2*i; } } if(num1<=num2) printf("Vladik\n"); else printf("Valera\n"); } return 0; }
我还想了一个等差数列求和的,wa了,也不想改了。。。
下一个题吧。。。
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P?=?[p1,?p2,?...,?pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
First line contains two space-separated integers n, m (1?≤?n,?m?≤?104) — length of permutation and number of times Vladik‘s mom sorted some subsegment of the book.
Second line contains n space-separated integers p1,?p2,?...,?pn (1?≤?pi?≤?n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1?≤?li?≤?xi?≤?ri?≤?n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn‘t changed, or "No" otherwise.
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Yes
No
Yes
Yes
No
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Yes
No
Yes
No
Yes
Explanation of first test case:
- [1,?2,?3,?4,?5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
- [3,?4,?5,?2,?1] — permutation after sorting, 1-st element has changed, so answer is "No".
- [5,?2,?3,?4,?1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
- [5,?4,?3,?2,?1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
- [5,?1,?2,?3,?4] — permutation after sorting, 3-rd element has changed, so answer is "No".
题意就是一堆数,从l到r,排个序,然后看第x个数有没有变。
这个题老大说如果用sort排序(时间复杂度O( n*log2(n) ))的话不行,会超时。
就换一个思路,统计l到r中有几个比第x个数小的数,然后统计的值和l到x中有几个数比较一下,如果相等,就不变,为Yes,否则为No;
A题写的好难过,还好B题一次就过了╭(╯^╰)╮。
代码:
#include<bits/stdc++.h> using namespace std; const int N=1e5; int a[N]; int main(){ int n,m; int h,k,l,num; while(~scanf("%d%d",&n,&m)){ for(int i=0;i<n;i++) scanf("%d",&a[i]); while(m--){ scanf("%d%d%d",&h,&k,&l); num=0; for(int i=h-1;i<=k-1;i++){ if(a[i]<a[l-1]) num++; } if(num==l-h) printf("Yes\n"); else printf("No\n"); } } return 0; }
这个题让我自己又想起了一个乱七八糟的题,输出第x个?
二分不可以(老大说的),最后结论是用主席树(°Д°),我写不出来(大讲座的时候学长也讲过(ノдヽ)),太菜太菜,加油吧。
下一题,虽然老大给我讲了,但是还是写不对???????,dp我不会(虽然大讲座的时候也有学长讲了(?ω?`ll))。。。(/~0~)/
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code ai is known (the code of the city in which they are going to).
Train chief selects some number of disjoint segments of the original sequence of people (covering entire sequence by segments is not necessary). People who are in the same segment will be in the same train carriage. The segments are selected in such way that if at least one person travels to the city x, then all people who are going to city x should be in the same railway carriage. This means that they can’t belong to different segments. Note, that all people who travel to the city x, either go to it and in the same railway carriage, or do not go anywhere at all.
Comfort of a train trip with people on segment from position l to position r is equal to XOR of all distinct codes of cities for people on the segment from position l to position r. XOR operation also known as exclusive OR.
Total comfort of a train trip is equal to sum of comfort for each segment.
Help Vladik to know maximal possible total comfort.
First line contains single integer n (1?≤?n?≤?5000) — number of people.
Second line contains n space-separated integers a1,?a2,?...,?an (0?≤?ai?≤?5000), where ai denotes code of the city to which i-th person is going.
The output should contain a single integer — maximal possible total comfort.
6
4 4 2 5 2 3
14
9
5 1 3 1 5 2 4 2 5
9
In the first test case best partition into segments is: [4,?4] [2,?5,?2] [3], answer is calculated as follows: 4?+?(2 xor 5)?+?3?=?4?+?7?+?3?=?14
In the second test case best partition into segments is: 5 1 [3] 1 5 [2,?4,?2] 5, answer calculated as follows: 3?+?(2 xor 4)?=?3?+?6?=?9.
这个题用dp写,不会。。。
要异或啥的。。。
写不对,以后再改,把老大的代码贴出来供着?( ′?∧?`)?
希望老大别打我。。。
代码:(老大的)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cctype> #include<cmath> #include<cstring> #include<map> #include<stack> #include<set> #include<vector> #include<algorithm> #include<string.h> typedef long long ll; typedef unsigned long long LL; using namespace std; const int INF=0x3f3f3f3f; const double eps=0.0000000001; const int N=500000+10; const int MAX=1000+10; struct node{ int x,y; }a[N]; int v[N]; int dp[N]; int vis[N]; int main(){ int n; while(scanf("%d",&n)!=EOF){ memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++){ scanf("%d",&v[i]); if(a[v[i]].x==0)a[v[i]].x=i; else a[v[i]].y=i; } for(int i=1;i<=n;i++){ memset(vis,0,sizeof(vis)); dp[i]=dp[i-1]; int ans=0; int minn=i; for(int j=i;j>=1;j--){ int t=v[j]; if(vis[t]==0){ if(a[t].y>i)break; minn=min(minn,a[t].x); ans=ans^t; vis[t]=1; } if(j<=minn)dp[i]=max(dp[i],dp[j-1]+ans); } } cout<<dp[n]<<endl; } }
以后懂了再滚回来改自己的垃圾代码。
打击!!_| ̄|○,菜呀,菜呀,菜的捂脸(/▽╲),
今天本来写一堆乱七八糟的作业就很受打击+快要考试+今晚写的题乱七八糟=菜的捂脸+???????+|墙|????;)+打击!!_| ̄|○
就这样吧,该滚去睡觉了,不想修仙。。。。(/~0~)/
最后,谢大佬(*/ω\*)
。。。(/~0~)/
以上是关于Codeforces Round #416的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #416 (Div. 2) A+B
Codeforces Round #416 (Div. 2) 811D Vladik and Favorite Game
Codeforces Round #416 (Div. 2)
(线段树+并查集) Codeforces Round #416 (Div. 2) E Vladik and Entertaining Flags
[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段