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,要么全都在该序列,要么全都不在该序列. 一个序列的价值是所有不同的值的异或和.整个的价值是所有划分出来的序列的价值之和. ...
随机推荐
- 2019 CCPC-Wannafly Winter Camp Day3(Div2, onsite)
solve 4/11 补题:5/11 A 二十四点* Code:pai爷 zz Thinking :pai爷 打表找规律,1张牌 10个不可能的 2张牌有 43 种不可能的 3张牌 有74 种不可能 ...
- this小结
this 对象是在运行时基于函数的执行环境绑定的: 全局函数中, this 等于 window 函数被作为某个对象的方法调用时, this 等于那个对象 匿名函数的执行环境具有全局性, this 指向 ...
- Docker入门笔记(1)
Docker入门笔记(1) 1.安装Docker yum -y install docker-ce 2.查看Docker版本 [root@localhost ~]# docker -v Docker ...
- 数据备份及恢复(mongodump/mongorestore)
说明 1.mongodump创建高保真的BSON文件,mongorestore可以用其恢复数据库.对于小型数据库的备份和恢复,这两个工具非常简单和高效,但对于大型数据库的备份并不理想.2.mongod ...
- excel表计算和计算器计算结果不一致
excel表计算和计算器计算结果不一致 : 建议安装完excel进行精度设置:
- [转]Hive 数据类型
Hive的内置数据类型可以分为两大类:(1).基础数据类型:(2).复杂数据类型.其中,基础数据类型包括:TINYINT,SMALLINT,INT,BIGINT,BOOLEAN,FLOAT,DOUBL ...
- jedis入门教程
1 jedis介绍 2 java连接Redis 1 导入jar包 2 连接实例 @Test //获得单一的jedis对象操作数据库 public void test1(){ //1.获得连接对象 设置 ...
- css消除空白节点的方法
在做配置页面的时候,出现一个现在现象,两个同样的div(外框尺寸也是一样的),div里面包含有三个小的div ,三个小的div宽度也是一样的,同为33.3%,但是出现奇怪现象的就是左边一个有滚动条,右 ...
- 使用c#特性,给方法或类打自定义标签再反射获取
给方法打自定义标签再反射获取 1.自定义特性类 using System; using System.Collections; using System.Collections.Generic; // ...
- Java虚拟机知识 总结 记录
总结了自己这两天掌握的一些JVM相关的知识.方便自己复习. jvm全称是Java Virtual Machine(java虚拟机).它之所以被称之为是“虚拟”的,就是因为它仅仅是由一个规范来定义的抽象 ...