#include<bits/stdc++.h>
using namespace std;intmain(){longlong a, b, c, d;
cin >> a >> b >> c >> d;longlong ans =(a+b+c+d)*(a+b+c+d)- a*a - b*b - c*c - d*d;
cout << ans /2;return0;}
青蛙跳
#include<bits/stdc++.h>
using namespace std;intmain(){int n, x1, x2, y1, y2, dx, dy;
cin >> n;while(n --){
cin >> x1 >> x2 >> y1 >> y2;
dx = x1 - x2;
dy = y1 - y2;if(dx ==0)puts("YES");elseif(dy ==0)puts("NO");elseif(dx % dy ==0&& dx / dy <0)puts("YES");elseputs("NO");}return0;}
结合律
#include<bits/stdc++.h>
using namespace std;intmain(){int a[2][2]={};
cin >> a[0][0]>> a[0][1]>> a[1][0]>> a[1][1];
bool flag = true;for(int i =0; i <8; i ++){int x = i %2;int y = i /2%2;int z = i /4;if(a[a[x][y]][z]!= a[x][a[y][z]]){
flag = false;}}if(flag)puts("Yes");elseputs("No");return0;}
石子游戏
#include<bits/stdc++.h>
using namespace std;intmain(){int T, a, b;
cin >> T;while(T --){
cin >> a >> b;if(a*b %2==0)puts("Alice");elseputs("Bob");}return0;}
吉利的数字
代码一
#include<bits/stdc++.h>
using namespace std;constint N =100009, M =10;int n, m, a[N], ans[N], num[M];intmain(){
string s;
cin >> s >> m;for(int i =0; i < m; i ++) cin >> num[i];sort(num, num + m);//先从低位 -> 高位,尽可能用大的数字 int t =0;//1:被低位借1当10; 0没被借位 for(int i = s.size()-1; i >=0; i --){int x = s[i]-'0'- t;if(x < num[0]&& i !=0) t =1, x +=10;else t =0;for(int j = m -1; j >=0; j --){if(num[j]<= x){
ans[i]= num[j];break;}}}//再从高位 -> 低位,如果高位有富余,则借给低位,借1当10
t =0;for(int i =0; i < s.size(); i ++){if(t ==1){
ans[i]= num[m-1];
t =1;}else{if(s[i]-'0'> ans[i]) t =1;else t =0;}}//去掉前导 0 int l =-1;for(int i =0; i < s.size(); i ++){if(ans[i]!=0){
l = i;break;}}if(l ==-1) cout <<-1;else{for(int i = l; i < s.size(); i ++) cout << ans[i];}return0;}
代码二
#include<bits/stdc++.h>
using namespace std;
namespace IN
{
string n;char a[10];int m;}
using namespace IN;intmain(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;for(size_t i =1; i <= m; i ++) cin >> a[i];sort(a +1, a + m +1);int len = n.size();
bool lst =0;// 0表示正常,1表示是退回来的
string ans ="";for(size_t i =0; i < len;)// 每一位数字{int cnt =0;for(size_t j = m; j >=1; j --)// 有m种选择{if(a[j]== n[i]&&!lst){
ans += a[j], i ++;break;}elseif(a[j]< n[i])// 因为是从大往小找,所以找到了肯定是最接近的{
ans += a[j], i ++;for(; i < len; i ++) ans += a[m];break;}else cnt ++;}if(cnt == m)// 说明没有≤n[i]的{if(len ==1){
cout <<-1;return0;}if(i ==0)for(i ++; i < len; i ++) ans += a[m];else ans[-- i]=' ', lst =1;// 退回去}}for(size_t i =0; i < ans.size(); i ++)if(ans[i]!=' '&&!(i==0&& ans[i]=='0')) cout << ans[i];return0;}