#include<bits/stdc++.h>usingnamespace std;longlonggcd(int x,int y){return!y?x:gcd(y,x % y);}intmain(){int T; cin >> T;while(T --){int a,b,c,d;int ans;
cin >> a >> b >>c >> d;if(a * d + a * c == b * d) cout <<0<< endl;else{longlongint up =abs(b * d - a *(d + c));longlongint down =abs(2* d * b);// cout << up << down;
cout << up /gcd(up,down)<<'/'<< down/gcd(up,down)<< endl;}}}
1386
#include<iostream>#include<cstring>#definelllonglongusingnamespace std;constint N =10010;int a[N],b[N],cnt;//求C(n,3) longlongC(int n){return n *(n -1)*1LL*(n -2)/6;}voidquick_sort(int q[],int l,int r){//递归的终止情况if(l >= r)return;//第一步:分成子问题int i = l -1, j = r +1, x = q[l + r >>1];while(i < j){do i++;while(q[i]< x);do j--;while(q[j]> x);if(i < j)swap(q[i], q[j]);}//第二步:递归处理子问题quick_sort(q, l, j),quick_sort(q, j +1, r);//第三步:子问题合并}intmain(){
ios::sync_with_stdio(false);int T; cin >> T;while(T --){int n;
cin >> n;//b数组存放分好颜色的球,b[i]即第i种颜色的球的个数,这里每个样例前初始化。 memset(b,0,sizeof b);for(int i =0;i < n;i ++)
cin >> a[i];//排序方便统计。 quick_sort(a,0,n-1);int j =0;int k;//遍历所有球,用双指针统计同一种颜色的球个数 for(int i =0;i < n;i ++){if(a[i]== a[i +1]){
k = i;while(a[i]== a[k]&& k < n){
b[j]++;
k ++;}
i = k -1;}
j ++;}longlong sum =0;for(int i =0;i < j;i ++){if(b[i]>=3) sum +=C(b[i]);if(b[i]>=2) sum+=b[i]*(b[i]-1)*1LL*(n-b[i])/2;}//取两种颜色:在两两组合的颜色里取三个球,双重循环。
cout <<C(n)- sum << endl;}}
1403
#include<iostream>usingnamespace std;//求边长 intfind(int x){int j;for(int i =1;i <=10;i ++){if(x >=(i -1)*(i -1)+1&& x <= i * i){
j = i;break;}}return j;}intmain(){int n;while(cin >> n){if(n ==0)return0;int a =find(n);//菱形最多的'/\' int up =(a * a - a)/2+ a;//菱形最多的'\/ int down =(a * a - a)/2;//上部分打印 int u0 =0;for(int i =0;i < a;i ++){//每行前面的空格 for(int j =0;j + i +1< a;j ++)printf(" ");//这一行的'/\' for(int j =0;j -1< i;j ++){
u0 ++;printf("/\\");if(u0 >= n)break;}//判断是否满上半部if(n == u0 && u0 < up)printf("/\n");elseprintf("\n");}//下部分打印int cnt = n - down;int u =0;for(int i =0;i < a;i ++){//打印空格 for(int j =0;j < i;j ++)printf(" ");//打印'\/'for(int j =0;j + i < a;j ++){
u ++;printf("\\/");if(u >= cnt)break;}if(u == cnt){printf("\n");break;}elseprintf("\n");}}}
1404
#include<iostream>#include<algorithm>#include<cmath>usingnamespace std;typedeflonglong LL;constint N =10010;
LL a[N];//上部分查询 intfind(int n){if(n ==1)return1;else{for(int i =1;i <= n;i ++)if(n > a[i]&& n <= a[i +1]){return i +1;break;}}}intmain(){//创造数列
a[1]=1;for(int i =2;i <= N;i ++)
a[i]= a[i -1]+ i;int T; cin >> T;while(T --){int s,st,ed; cin >> s >> st >> ed;int row1,col1,row2,col2;//行和列和菱形的行 //中间值int div =(s * s + s)/2;if(st > div - s && st <= div){
row1 = div - st +1;
col1 = s +1- row1;}elseif(st > div)//转化成上部分 {
st = s * s +1- st;
col1 = st - a[find(st)-1];
row1 =find(st)+1- col1;
col1 = s +1- col1;
row1 = s +1- row1;}else{
col1 = st - a[find(st)-1];
row1 =find(st)+1- col1;}//特判:若是在正方形的对角线if(ed > div - s && ed <= div){
row2 = div - ed +1;
col2 = s +1- row2;}elseif(ed > div){
ed = s * s +1- ed;
col2 = ed - a[find(ed)-1];
row2 =find(ed)+1- col2;
col2 = s +1- col2;
row2 = s +1- row2;}else{
col2 = ed - a[find(ed)-1];
row2 =find(ed)+1- col2;}//曼哈顿距离
cout <<abs(row1 - row2)+abs(col1 - col2)<<'\n';}return0;}
1406
#include<iostream>#include<algorithm>usingnamespace std;char a[110],b[110];int c[26];intmax_char(char s[],int n){for(int i =0;i < n;i ++){
c[s[i]-'a']++;}sort(c,c+26);return c[25];}intmain(){
ios::sync_with_stdio(false);int n; cin >> n;while(n --){int m,k;//m个字母,k个调换次数。
cin >> m >>k;//轮次。// k = (k >= m)?k/m:k;// cout << k << endl;for(int i =0;i < m;i ++){
cin >> a[i];}for(int i =0;i < m;i ++){
cin >> b[i];}//初始化 for(int i =0;i <26;i++) c[i]=0;int max_1 =max_char(a,m);for(int i =0;i <26;i++) c[i]=0;int max_2 =max_char(b,m);// cout << max_1 <<" " << max_2 << endl;if(m == max_1 && k ==1) max_1 = m -1;else max_1 =min(max_1 + k,m);if(m == max_2 && k ==1) max_2 = m -1;else max_2 =min(max_2 + k,m);// cout << max_1 <<" " << max_2 << endl;if(max_1 > max_2) cout <<"Alice"<<'\n';elseif(max_1 < max_2) cout <<"Bob"<<'\n';else cout <<"Draw"<<'\n';}return0;}
1411
#include<iostream>usingnamespace std;int h[100000010];intmain(){
ios::sync_with_stdio(false);int T; cin >>T;while(T --){longlong n; cin >> n;int j;if(n <=2) cout <<2<<'\n';else{//统计各数码出现次数 for(int i =2;i <= n -1;i ++){for(j =0;j < i;j ++) h[j]=0;longlong u = n;while(u){longlongint t0 = u % i;
h[t0]++;
u/=i;}int maxn =0;int minn =1e9;for(j =0;j < i;j ++){if(h[j]){
maxn =max(h[j],maxn);
minn =min(h[j],minn);}}if(maxn == minn){
cout << i <<'\n';break;}}}//每个进制的枚举 }}
1412
#include<iostream>usingnamespace std;int a[4][4];int b1[12],b2[4];intmain(){int T; cin >>T;while(T --){//存数 for(int i =0;i <4;i ++)for(int j =0;j <4;j ++)
cin >> a[i][j];
b2[0]= a[1][1];b2[1]= a[1][2];b2[2]= a[2][2];b2[3]= a[2][1];int max_1 =0,max_2 =0,max_3 =0;//外圈三个数和内圈两个数 int col =0,row =0;//1求外圈的最大连续三个数加上内圈最大数int cnt =0;while(row ==0&& col <=3){
b1[cnt ++]= a[row][col];
col ++;}
col --;row ++;while(col ==3&& row <=3){
b1[cnt ++]= a[row][col];
row ++;}
row --;col --;while(row ==3&& col >=0){
b1[cnt ++]= a[row][col];
col --;}
col ++;row --;while(col ==0&& row >=0){
b1[cnt ++]= a[row][col];
row --;}
max_1 =max(b1[0]+ b1[10]+ b1[11],b1[11]+ b1[0]+ b1[1]);for(int i =0;i <10;i ++)
max_1 =max(max_1,b1[i]+b1[i +1]+ b1[i +2]);int t = b2[0];for(int i =0;i <4;i ++) t =max(t,b2[i]);
max_1 += t;//2求外圈的最大连续两个数加上内圈最大连续两个数
max_2 = b1[0]+ b1[11];for(int i =0;i <11;i ++)
max_2 =max(max_2,b1[i]+b1[i +1]);
t = b2[0]+ b2[3];for(int i =0;i <3;i ++) t =max(t,b2[i]+ b2[i +1]);
max_2 += t;//3求内圈的和
max_3 = a[1][1]+ a[1][2]+ a[2][1]+ a[2][2];
max_1 =max(max_1,max_2);
max_1 =max(max_1,max_3);
cout << max_1 <<'\n';// for(int i = 0;i < 12;i ++) cout << b1[i] <<' ';// puts("");// for(int j = 0;j < 4;j ++) cout << b2[j] << ' ';}return0;}
1415
#include<iostream>usingnamespace std;typedeflonglong LL;constint N =50010;intmain(){
ios::sync_with_stdio(false);
LL a[N],s[N];int T; cin >> T;while(T--){
LL n,p;
cin >> n >> p;for(int i =0;i < n;i ++){
cin >> a[i];
s[i +1]= s[i]+ a[i];//s从1下标开始 }
LL sum =0;for(int i =1;i < n;i ++){
LL t = s[i];
LL t0 = s[n]- s[i];
sum =max(sum,t % p + t0 % p);}
cout << sum <<'\n';}return0;}
1425
#include<iostream>#include<cstring>usingnamespace std;intmain(){char s[210];int m =0;while(~scanf("%s",s)&& m <1000){
m ++;int a[6]={1,6,5,2,3,4};for(int i =0;i <strlen(s);i ++){int u,b,c,d;if(s[i]=='U'){
u = a[0]; b = a[1]; c = a[2]; d = a[3];
a[0]= c;
a[1]= d;
a[2]= b;
a[3]= u;}elseif(s[i]=='D'){
u = a[0]; b = a[1]; c = a[2]; d = a[3];
a[0]= d;
a[1]= c;
a[2]= u;
a[3]= b;}elseif(s[i]=='L'){
u = a[0]; b = a[1]; c = a[4]; d = a[5];
a[0]= d;
a[1]= c;
a[4]= u;
a[5]= b;}elseif(s[i]=='R'){
u = a[0]; b = a[1]; c = a[4]; d = a[5];
a[0]= c;
a[1]= d;
a[4]= b;
a[5]= u;}elseif(s[i]=='X'){
u = a[2]; b = a[3]; c= a[4]; d = a[5];
a[2]= d;
a[3]=c;
a[4]=u;
a[5]= b;}elseif(s[i]=='Y'){
u = a[2]; b = a[3]; c= a[4]; d = a[5];
a[2]= c;
a[3]=d;
a[4]=b;
a[5]= u;}}printf("%d\n",a[0]);}}