Codeforces Round #416 (Div.2)
来源:互联网 发布:nginx root详解 编辑:程序博客网 时间:2024/06/14 22:14
A.
题意:Vladik给Valera一颗糖,Valera给Vladik两颗糖,Vladik再给Valera三颗糖......输出最先糖数不够给的人
解题思路:for循环,糖数不够作为循环结束的条件
代码:
#include <bits/stdc++.h>using namespace std;typedef long long int ll;int main(){ ll a,b; while(cin>>a>>b) { for(int i=1;i<=1000000000;i++) { if(i%2)a-=i; else b-=i; if(a<0||b<0)break; } if(a<0)cout<<"Vladik"<<endl; else if(b<0)cout<<"Valera"<<endl; } return 0;}
题意:n个数,m组样例,每组数据包括三个整数l,r,x,将[l,r]区间内的数字按升序排列,判断重排后的第x个数与之前未重排时的数字是否相同
解题思路:将n个数用一维数组存起来,这里不能直接用sort模拟过程会超时,要先求区间[l,r]内比p[x]小的数字的个数,因为按升序排列之后比它小的数字就会排到它的前面,这时就要判断p[x]这个数当前所在的位置还是不是x了,这个方法真的很巧妙
代码:
#include <bits/stdc++.h>using namespace std;int n,m,l,r,x;int p[10005];int solve(int l,int r,int x){ int cnt=0,num=0; for(int i=l;i<=r;i++) { if(p[i]<p[x])cnt++; } if(cnt+l==x)return 1; return 0;}int main(){ while(cin>>n>>m) { for(int i=1;i<=n;i++) { cin>>p[i]; } for(int i=0;i<m;i++) { cin>>l>>r>>x; if(solve(l,r,x))cout<<"Yes"<<endl; else cout<<"No"<<endl; } } return 0;}
阅读全文
0 0
- Codeforces Round #416 (Div. 2)
- Codeforces Round #416 (Div. 2)
- Codeforces Round #416 (Div.2)
- Codeforces Round #416 (Div. 2) ABC
- Codeforces Round #416 (Div. 2) 题解
- Codeforces Round #416 (Div. 2) C
- Codeforces Round #416 (Div. 2)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- 使用某些框架出现simplexml_load_string()的原因以及解决方案
- TypeScript 枚举使用整理
- springmvc前后端数据交互总结
- 不关闭防火墙 也能ping通机器
- update 批量修改,oracle多表关联修改
- Codeforces Round #416 (Div.2)
- GreenDao3.0 学习笔记——导入以及注解
- Ubuntu 16.04 下使用 MySQL 5.7 + PHP 7 + Apache 部署 Nextcloud
- 欢迎使用CSDN-markdown编辑器
- 《嵌入式Linux应用开发完全手册》---开篇
- HashMap实现原理分析
- NP-complete problems
- android中的长按复制
- linux shell eval命令