Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy
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:
题目链接:http://codeforces.com/contest/811/problem/A
分析:感觉没什么说的,照着写吧,我也不知道该死的竟然WA了三发,QAQ
下面给出AC代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n,m; 6 while(scanf("%d%d",&n,&m)!=EOF) 7 { 8 for(int i=1;;i+=2) 9 { 10 if(n>=i) 11 n-=i; 12 else 13 { 14 printf("Vladik\n"); 15 return 0; 16 } 17 if(m>=i+1) 18 m-=(i+1); 19 else 20 { 21 printf("Valera\n"); 22 return 0; 23 } 24 } 25 } 26 return 0; 27 }
B. Vladik and Complicated Book
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".
题目链接:http://codeforces.com/contest/811/problem/B
分析:给出一个1~n的排列 m次询问一个区间[l,r]排序后原来x位置的数是否改变
可以直接找[l,r]中x的值的前面的数字个数,然后判断b==x-l+1是否成立,成立为Yes!
下面给出AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,m,a[10010],b; 4 int main() 5 { 6 scanf("%d%d",&n,&m); 7 for(int i=1;i<=n;i++) 8 scanf("%d",a+i); 9 for(int i=1;i<=m;i++) 10 { 11 int l,r,x; 12 scanf("%d%d%d",&l,&r,&x); 13 b=0; 14 for(int i=l;i<=r;i++) 15 if(a[i]<=a[x]) 16 b++; 17 puts(b==x-l+1?"Yes":"No"); 18 } 19 return 0; 20 }
作 者:Angel_Kitty
出 处:https://www.cnblogs.com/ECJTUACM-873284962/
关于作者:阿里云ACE,目前主要研究方向是Web安全漏洞以及反序列化。如有问题或建议,请多多赐教!
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信我
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是作者坚持原创和持续写作的最大动力!
欢迎大家关注我的微信公众号IT老实人(IThonest),如果您觉得文章对您有很大的帮助,您可以考虑赏博主一杯咖啡以资鼓励,您的肯定将是我最大的动力。thx.
我的公众号是IT老实人(IThonest),一个有故事的公众号,欢迎大家来这里讨论,共同进步,不断学习才能不断进步。扫下面的二维码或者收藏下面的二维码关注吧(长按下面的二维码图片、并选择识别图中的二维码),个人QQ和微信的二维码也已给出,扫描下面👇的二维码一起来讨论吧!!!
欢迎大家关注我的Github,一些文章的备份和平常做的一些项目会存放在这里。