A.Card Game

题目大意:两个人都有共有n张卡牌,每张卡牌上都有一个数xi,没有两张牌上的数相同,且xi不小于1不大于n。每次两个人选出一张牌来,牌上数字大的人赢得此局,如果谁最后手上拥有所有的n张牌,那么他取得胜利。

分析:只要判断数字为n的牌在谁的手里即可。

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n,k1,k2,x;
cin>>t;
while(t--){
cin>>n>>k1>>k2;
int f = ;
for(int i=;i<k1;i++){
cin>>x;
if(x==n) f=;
}
for(int i=;i<k2;i++){
cin>>x;
if(x==n) f=;
}
if(f==) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

B.Interesting Subarray

题目大意:问你是否能找到一个连续子序列,使得这段子序列里最大值减最小值大于等于这段子序列的长度。

分析:只用比较相邻的两个数即可。

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int a[maxn];
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
for (int i = ; i <= n; i++)
cin >> a[i];
bool f = false;
int l = -, r = -;
for (int i = ; i <= n - ; i++) {
if (abs(a[i] - a[i + ]) >= ) {
f = true;
l = i;
r = i + ;
}
}
if (f) {
cout << "YES" << endl;
cout << l << " " << r << endl;
} else {
cout << "NO" << endl;
}
}
return ;
}

C. Make Good

题目大意:让你再找几个ai,使得a1+a2+...+an=2*(a1^a2^...^an)。

分析:就直接构造一个最简单的方法出来就行了,因为添加的元素个数没有限制到最少。

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
typedef long long ll;
ll a[maxn];
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
for (int i = ; i <= n; i++)
cin >> a[i];
ll l = a[], r = a[];
for (int i = ; i <= n; i++) {
l += a[i];
r ^= a[i];
}
//l+x/2 = 2*(r^x) 2*l+x=4*(r^x)
//1/2*l+x/4 = r^x
cout << << endl;
cout << r << " " << l + r << endl;
}
return ;
}

最新文章

  1. 最好用的Unity版本控制工具
  2. javascript中apply、call和bind的区别
  3. java 500/404错误总结
  4. Multiple MySQL running but PID file could not be found
  5. (oracle/mysql)启停,导入导出,DB字符集
  6. [转载]:Delphi xe7并行编程快速入门
  7. 制作3D图片立方体旋转特效
  8. Sqli-labs less 54
  9. Oracle-11g-R2 RAC 环境下 GPnP Profile 文件
  10. BZOJ1726: [Usaco2006 Nov]Roadblocks第二短路
  11. BeanFactory调用getbean()对象
  12. RichEditBox 使用自定义菜单
  13. 修改Request 中的数据
  14. wordpress怎么禁止文章复制
  15. script id
  16. 使用java操作kudu
  17. redis启动出错Creating Server TCP listening socket 127.0.0.1:6379: bind: No error
  18. [svc]inotify+rsync解决nfs单点问题
  19. poj1273
  20. CCCC训练赛一些模板 struct sstream

热门文章

  1. 快速幂 &amp; 矩阵快速幂
  2. keil条件断点
  3. linux中cp指令前面加反斜杠
  4. 页面美化代码1.x
  5. R rep() 函数
  6. Redis的安装配置及简单集群部署
  7. 那些年我们踩过的坑,SQL 中的空值陷阱!
  8. 算法设计与分析 - 李春葆 - 第二版 - pdf-&gt;word v1
  9. UISearchBar设置背景色
  10. css 图形样式