博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #416 (Div. 2) A+B
阅读量:5099 次
发布时间:2019-06-13

本文共 4623 字,大约阅读时间需要 15 分钟。

A. Vladik and Courtesy
2 seconds
256 megabytes
 

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.

Input

Single line of input data contains two space-separated integers ab (1 ≤ a, b ≤ 109) — number of Vladik and Valera candies respectively.

Output

Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.

 
input
1 1
output
Valera
input
7 6
output
Vladik
Note:

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块....直到有一方无法送出相应的糖果时结束。

     输出对应的人名。

解题思路:暴力模拟即可。

1 #include 
2 int main () 3 { 4 int a,b; 5 while (~scanf("%d%d",&a,&b)) 6 { 7 for (int i = 1;a>=0&&b>=0; i ++) 8 { 9 if (i%2) a-= i;10 else b -= i;11 }12 if (a < 0)13 printf("Vladik\n");14 else15 printf("Valera\n");16 }17 return 0;18 }
View Code

 

 

B. Vladik and Complicated Book
 
2 seconds
256 megabytes
 

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.

Input

First line contains two space-separated integers nm (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 lirixi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.

Output

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.

 
input
5 5 5 4 3 2 1 1 5 3 1 3 1 2 4 3 4 4 4 2 5 3
output
Yes No Yes Yes No
input
6 5 1 4 3 2 5 6 2 4 3 1 6 2 4 5 4 1 3 3 2 6 3
output
Yes No Yes No Yes
Note:

Explanation of first test case:

  1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
  2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
  3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
  4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
  5. [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的位置

1 #include 
2 int main () 3 { 4 int n,m,i,l,r,x; 5 int p[10010]; 6 while (~scanf("%d%d",&n,&m)) 7 { 8 for (i = 1; i <= n; i ++) 9 scanf("%d",&p[i]);10 while (m --)11 {12 int sum = 0;13 scanf("%d%d%d",&l,&r,&x);14 for(i = l; i <= r; i ++)15 if (p[i] < p[x])16 sum ++;17 if (x-l == sum)18 printf("Yes\n");19 else20 printf("No\n");21 }22 }23 return 0;24 }

 

转载于:https://www.cnblogs.com/yoke/p/6914768.html

你可能感兴趣的文章
MySQL更改默认的数据文档存储目录
查看>>
替代微软IIS强大的HTTP网站服务器工具
查看>>
6.5 案例21:将本地数据库中数据提交到服务器端
查看>>
PyQt5--EventSender
查看>>
android 通过AlarmManager实现守护进程
查看>>
Sql Server 中由数字转换为指定长度的字符串
查看>>
win7下把电脑设置成wlan热
查看>>
Java 多态 虚方法
查看>>
jquery.validate插件在booststarp中的运用
查看>>
java常用的包
查看>>
PHP批量覆盖文件并执行cmd命令脚本
查看>>
Unity之fragment shader中如何获得视口空间中的坐标
查看>>
支持向量机——内核
查看>>
MFC注册热键
查看>>
万能的SQLHelper帮助类
查看>>
如何在 Terminal 内可以“用惯用的编辑器”快速打开“目前正在做”的专案(project)呢?...
查看>>
uboot分析:uboot的启动过程分析
查看>>
tmux的简单快捷键
查看>>
springboot笔记04——读取配置文件+使用slf4j日志
查看>>
[Swift]LeetCode653. 两数之和 IV - 输入 BST | Two Sum IV - Input is a BST
查看>>