有段时间没练了,十几分钟过一道题本来还兴奋呢,第二道直接卡死,还是继续努力吧
A - Game with Cards
简单题
思路:对两人的牌进行排序,谁有最大牌且先出则能赢
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m;
int T;
int a[N];
int b[N];
int main()
{
cin>>T;
while(T -- ){
cin>>n;
for(int i = 0; i < n; i ++ ){
cin>>a[i];
}
cin>>m;
for(int i = 0; i < m; i ++ ){
cin>>b[i];
}
sort(a, a + n);
sort(b, b + m);
if(a[n - 1] > b[m - 1]){
cout<<"Alice"<<endl;
cout<<"Alice"<<endl;
}
else if(a[n - 1] == b[m - 1]){
cout<<"Alice"<<endl;
cout<<"Bob"<<endl;
}
else if(a[n - 1] < b[m - 1]){
cout<<"Bob"<<endl;
cout<<"Bob"<<endl;
}
}
return 0;
}
B - Card Trick
思维题,刚开始没想出来,看题解也不太明白,感谢大佬点拨
思路:考虑当b1+b1=n时,相当于不改变数组,所以把b数组所有数加起来对n取模,剩下哪个数就是会对数组造成影响的,假如剩下的是3,对将数组前三个数翻转后,最上面的数刚好是a[3](下标为3),所以答案就出来了,记住考虑范围,对b数组累加这一步会爆int,所以直接用过long long
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N];
int t, n, m;
int main()
{
cin>>t;
while(t -- ){
long long sum = 0;
cin>>n;
for(int i = 0; i < n; i ++ ){
cin>>a[i];
}
cin>>m;
for(int i = 0; i < m; i ++ ){
cin>>b[i];
sum += b[i];
}
cout<<a[sum % n]<<endl;
}
return 0;
}