#include<bits/stdc++.h>usingnamespace std;constint N =100010;int n;int q[N];intmain(){scanf("%d",&n);for(int i =0; i < n; i ++)scanf("%d",&q[i]);int res[3];
res[0]= q[0]*2, res[1]= q[n -1]*2;if(n %2) res[2]= q[n /2]*2;else res[2]= q[n /2-1]+ q[n /2];sort(res, res +3);for(int i =2; i >=0; i --)if(res[i]%2)printf("%.1lf ", res[i]/2.0);elseprintf("%d ", res[i]/2);return0;}
二十四点
实现
#include<bits/stdc++.h>usingnamespace std;
stack<int> num;
stack<char> op;voideval(){int b = num.top(); num.pop();int a = num.top(); num.pop();char c = op.top(); op.pop();int x;if(c =='+') x = a + b;elseif(c =='-') x = a - b;elseif(c =='x') x = a * b;else{if(a * b >=0) x = a / b;else// 向下取整。C++中a/b是向零取整{if(a % b ==0) x = a / b;else x = a / b -1;}}
num.push(x);}intmain(){
unordered_map<char,int> pr;//定义运算符的优先级
pr['+']= pr['-']=1;
pr['x']= pr['/']=2;int n;
cin >> n;while(n --){
string str;
cin >> str;
num =stack<int>();
op =stack<char>();for(auto c: str)if(c >='0'&& c <='9') num.push(c -'0');//是数字则之间压入数字栈else{while(op.size()&& pr[op.top()]>= pr[c])eval();//当前运算符优先级更低 进行运算
op.push(c);}while(op.size())eval();if(num.top()==24)puts("Yes");elseputs("No");}return0;}
损坏的RAID5
实现
#include<bits/stdc++.h>usingnamespace std;int n,s,l;int k;constint N =1010, M =40*1024*8+10;unsignedint disk[N][M /8];bool st[N];char str[M];unsignedintget(char c){if(c<='9')return c-'0';return c-'A'+10;}inlinecharget(unsignedint x){if(x <=9)return x +'0';return x -10+'A';}inline string u2s(unsignedint x){
string res;for(int i =7; i >=0; i --)
res +=get(x >>(i <<2)&15);return res;}intmain(){int len;
cin>>n>>s>>l;for(int i=0;i<l;i++){scanf("%d",&k);getchar();fgets(str, M,stdin);
st[k]=1;int sz =strlen(str)-1;for(int j=0;j<sz;j+=8){unsignedint x =0;for(int k=0;k<8;k++){
x =(x<<4)+get(str[j+k]);}
disk[k][j>>3]= x;//cout<<x<<endl;}
len = sz>>3;}int m,b;
cin>>m;while(m--){
cin>>b;if(b>=(n-1)*len)puts("-");else{int k = b/s;int hang = k/(n-1);int lie = k%(n-1);
lie =(lie+n-(hang)%n)%n;int r = hang * s + b % s;if(st[lie]){puts(u2s(disk[lie][r]).c_str());}elseif(l==n-1){unsignedint x =0;for(int i =0; i < n; i ++) x ^= disk[i][r];puts(u2s(x).c_str());}elseputs("-");}}}