刷題證明
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int t,x,y;
cin>>t;
while(t--)
{
cin>>x>>y;
if(x==y)
{
cout<<x+y<<endl;
}
else
{
cout<<x+y+(abs(x-y)-1)<<endl;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, q;
string s;
int sum[100005] = { 0 };
int main()
{
int x = 0;
cin >> n >> q;
cin >> s;
for (int i = 1; i <= s.size(); i++)
{
x = s[i - 1] - '`';
sum[i] =sum[i-1]+ x;
}
while (q--)
{
int begin, end;
cin >> begin >> end;
cout << sum[end] - sum[begin-1] << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
int t;
cin >> t;
while (t--)
{
int pos = 0;
int ans = 0;
cin >> s;
int len = s.size();
for (int i = 0; i < len; i++)
{
if (s[i] != 'a')
{
pos = len - i ;
ans = 1;
break;
}
}
if (ans == 1)
{
printf("YES\n");
for (int i = 0; i < pos; i++)
{
cout << s[i];
}
cout << 'a';
for (int i = pos; i < len; i++)
{
cout << s[i];
}
cout << "\n";
}
else if (ans == 0)
{
printf("NO\n");
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
int t;
cin>>t;
while(t--)
{
int len,sum;
cin>>len>>sum;
int x=len-len/2+(len%2==0);
cout<<sum/x<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
char a[110];
while (t--)
{
int len, check;
cin >> len;
check = len;
cin >> a;
for (int i = 0; i < len; i++)
{
if (a[i] != '?')
{
check = i;
break;
}
}
if (check ==len)
{
a[len] = 'B';
}
for (int i = check - 1; i >= 0; i--)
{
if (a[i] != '?')
{
continue;
}
if (a[i + 1] == 'B')
{
a[i] = 'R';
}
if (a[i + 1] == 'R')
{
a[i] = 'B';
}
}
for (int i = check + 1; i < len; i++)
{
if (a[i] != '?')
{
continue;
}
if (a[i - 1] == 'B')
{
a[i] = 'R';
}
if (a[i - 1] == 'R')
{
a[i] = 'B';
}
}
for (int i = 0; i < len; i++)
{
cout << a[i];
}
cout << endl;
memset(a, '0', len);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string s;
int main(void)
{
int t, n, k;
cin >> t;
while (t--)
{
cin >> n >> k;
cin >> s;
int no= 0;
for (int i = 0, j = n - 1; i < j - 1; i++, j--)
{
if (s[i] != s[j])
{
break;
}
no++;
}
if (no>= k)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
fill(s.begin(), s.end(), 0);
}
return 0;
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
int mh[1000010];
int ma[1000010];
signed main()
{
int t, a, h, mn;
cin >> t;
while (t--)
{
int damage = 0;
int residualBlood = 0;
cin >> a >> h >> mn;
for (int i = 0; i < mn; i++)
{
cin >> ma[i];
}
for (int i = 0; i < mn; i++)
{
cin >> mh[i];
}
for (int i = 0; i < mn; i++)
{
damage =damage+(mh[i] / a + (mh[i] % a != 0)) * ma[i];
}
for (int i = 0; i < mn; i++)
{
if (h - damage + ma[i] > 0)
{
cout << "YES" << endl;
residualBlood++;
break;
}
}
if (residualBlood == 0)
{
cout << "NO" << endl;
}
}
return 0;
}
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll t, len;
char checkn[12];
char s[55];
signed main()
{
cin >> t;
while (t--)
{
int ans = 0;
cin >> len;
memset(s, '0', len);
memset(checkn, '0', 11);
cin >> s;
for (int i = 0; i < len; i++)
{
checkn[s[i] - '0']++;
if (s[i] == '1' || s[i] == '4' || s[i] == '6' || s[i] == '8' || s[i] == '9')
{
printf("1\n");
cout << s[i] - '0' << endl;
ans = 1;
break;
}
}
if (ans == 1)continue;
for (int i = 0; i < len; i++)
{
if ((s[i] == '2' || s[i] == '5') && (i != 0))
{
cout << "2" << endl << s[i - 1] - '0' << s[i] - '0' << endl;
ans = 1;
break;
}
else if ((s[i] == '3' || s[i] == '7') && checkn[s[i] - '0']-'0' >= 2) {
cout << "2" << endl << s[i] - '0' << s[i] - '0' << endl;
ans = 1;
break;
}
}
if (ans == 0)
{
if (s[0] == '2')
cout << "2" << endl << "27" << endl;
else
cout << "2" << endl << "57" << endl;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int t, n, s[1001];
int x;
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> s[i];
}
sort(s, s + n);
x = 0;
for (int i = 1; x!=1 && i < n; i++)
{
if (s[i] == s[i - 1])
x = 1;
}
if (x == 1)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
return 0;
}