Codeforces Round #416 (Div. 2) A+B
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, theydon’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:

题目大意:
Vladik and Valera 各有a块和b块糖,他两个轮流送给对方糖果,Vladik and Valera 1块、
Valera送给Vladik 2块、Vladik and Valera 3块....直到有一方无法送出相应的糖果时结束。
输出对应的人名。
解题思路:暴力模拟即可。
#include <stdio.h>
int main ()
{
int a,b;
while (~scanf("%d%d",&a,&b))
{
for (int i = ;a>=&&b>=; i ++)
{
if (i%) a-= i;
else b -= i;
}
if (a < )
printf("Vladik\n");
else
printf("Valera\n");
}
return ;
}
2 seconds
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".
题目大意:
输入n个整数,然后有m次询问。每次询问输入三个整数L,R,X,将[L,R]范围内的整数从小到大排序,
判断第X个整数的位置是否发生变化。
解题思路:
下午写的时候,特意看了下数据范围,发现不是太大就直接sort了。不过最后被无情的hack了。。。。
后来在codeforces群里看大佬们讨论时提到一种思路,对于每一个询问只用判断[L,R]中小于第X个整数的个数
是否等于X-L(因为 (1 ≤ li ≤ xi ≤ ri ≤ n) 所以只要在[L,R]中有X-L个整数小于Xi排序之后就不会影响Xi的位置)
#include <stdio.h>
int main ()
{
int n,m,i,l,r,x;
int p[];
while (~scanf("%d%d",&n,&m))
{
for (i = ; i <= n; i ++)
scanf("%d",&p[i]);
while (m --)
{
int sum = ;
scanf("%d%d%d",&l,&r,&x);
for(i = l; i <= r; i ++)
if (p[i] < p[x])
sum ++;
if (x-l == sum)
printf("Yes\n");
else
printf("No\n");
}
}
return ;
}
Codeforces Round #416 (Div. 2) A+B的更多相关文章
- Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round#416 Div.2
A. Vladik and Courtesy 题面 At regular competition Vladik and Valera won a and b candies respectively. ...
- Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
http://codeforces.com/contest/811/problem/C 题意: 给出一行序列,现在要选出一些区间来(不必全部选完),但是相同的数必须出现在同一个区间中,也就是说该数要么 ...
- Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
地址:http://codeforces.com/contest/811/problem/D 题目: D. Vladik and Favorite Game time limit per test 2 ...
- Codeforces Round #416(Div. 2)-811A.。。。 811B.。。。 811C.dp。。。不会
CodeForces - 811A A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 meg ...
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
B. Vladik and Complicated Book time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- Codeforces Round #416 (Div. 2)A B C 水 暴力 dp
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 【分类讨论】【spfa】【BFS】Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
那个人第一步肯定要么能向下走,要么能向右走.于是一定可以判断出上下是否对调,或者左右是否对调. 然后他往这个方向再走一走就能发现一定可以再往旁边走,此时就可以判断出另一个方向是否对调. 都判断出来以后 ...
- 【动态规划】 Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
划分那个序列,没必要完全覆盖原序列.对于划分出来的每个序列,对于某个值v,要么全都在该序列,要么全都不在该序列. 一个序列的价值是所有不同的值的异或和.整个的价值是所有划分出来的序列的价值之和. ...
随机推荐
- ssh协议git利用ss代理
前言 不知道ss为何物的绕道 求帐号的绕道 这里只是亲测 ssh协议下的git, 如何判断是什么协议出门左拐 判断是否需要代理 我遇到的问题是: ssh_exchange_identification ...
- 【算法笔记】B1045 快速排序
1045 快速排序 (25 分) 著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边. 给定划分后 ...
- Pycharm与github的秘密
GIT介绍 GIT文章请看老男孩教育-银角大王的博客: http://www.cnblogs.com/wupeiqi/articles/7295372.html Git 是一个开源的分布式版本控制软件 ...
- python 小练习('''产生了多少个对象''')('''模拟两个英雄,昵称,攻击力,生命值''')
'''小练习 计数器,产生了多少个对象''' # class Student: # school = 'luffycity' # count = 0 # def __init__(self, name ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- git遇到的常见错误整理
远程仓库与本地代码不一致 解决: git pull --rebase git@gitee.com:l544402029/MUTAO.git 将仓库里的代码pull下来 ,然后重新进行git add ...
- 使用Jmeter进行http接口性能测试(转载)
在进行网页或应用程序后台接口开发时,一般要及时测试开发的接口能否正确接收和返回数据,对于单次测试,Postman插件是个不错的Http请求模拟工具. 但是Postman只能模拟单客户端的单次请求,而对 ...
- lfs
LFS──Linux from Scratch,就是一种从网上直接下载源码,从头编译LINUX的安装方式.它不是发行版,只是一个菜谱,告诉你到哪里去买菜(下载源码),怎么把这些生东西( raw c ...
- nginx, flask, wsgi
原来自己还没搞懂这些. 首先post一个观点: nginx应该是没解析任何东西,就判断是不是http请求,然后转发?或者判断是不是tcp请求,然后转发. 所以给了python后台就可以用wsgi解包. ...
- Spring异常:Annotation-specified bean name.. for bean class ...
Spring重命名问题.对照项目中的注解,查找@Service是否重重名.由于Spring是在注解下按配置扫描的方式去创建对象的,那么两个重名的注解也就不成立了. 备注,特别注意test包下有没有通过 ...