A. Vasya and Coins
题意:求a个一元硬币和b个两元硬币不能组成的最小金额。
思路:如果没有1元硬币,结果就是1;如果没有两元硬币结果就是1元硬币的个数加1;如果都有,那就是总金额加1。
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int a,b;
cin >> a >> b;
if(a==0)
cout << 1;
else if(b==0)
cout << a+1;
else
cout << a+b*2+1;
cout << endl;
}
return 0;
}
B - Vlad and Candies
题意:n种糖果,个数分别是ai个,每次取最多的糖果,如果连续取到同一个就输出NO,否则输出YES。
思路:如果第一次和第二次都是取一样的糖果,就输出NO了,即最大的糖果数量比第二大的数量大两个以上。
代码:
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
for(int i=0;i<n;i++)
cin >> a[i];
sort(a,a+n);
if(a[n-1]-a[n-2]>1)
cout << "NO";
else
cout << "YES";
cout << endl;
}
return 0;
}
55┭┮﹏┭┮奈何自己太菜,后面a不出来了。