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