A题 Average
//这题就是求和减去最大值和最小值然后除以n-2
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)&&n){
int Max = -1;
int Min = 110;
int sum = 0;
for(int i = 0;i < n;i++){
int t;
scanf("%d",&t);
sum += t;
Max = max(Max,t);
Min = min(Min,t);
}
sum -= Max;
sum -= Min;
n -= 2;
printf("%.1f
",(double)sum/n);
}
return 0;
}
B题 A+BIV
//暴力模拟a和b分别不断去乘以十,看谁的次数少,注意b的话输出是负值
#include<bits/stdc++.h>
using namespace std;
int main(){
int T;
scanf("%d",&T);
while(T--){
int a,b,c;
scanf("%d+%d=%d",&a,&b,&c);
int o = a;
int p = b;
int q = c;
int i = -1;
while(i++<10&&o+p!=q){
o*=10;
}
o = a;
p = b;
q = c;
int j = -1;
while(j++<10&&o+p!=q){
p*=10;
}
if(i<=j)printf("%d
",i);
else printf("%d
",-j);
}
return 0;
}
C题
//用到韦达定理(a+b)平方-4a*b=(a-b)平方,然后判断a-b是不是整数,在判断这样解得的a和b是不是整数就可以了
#include<bits/stdc++.h>
using namespace std;
int main(){
int T;
scanf("%d",&T);
while(T--){
__int64 a,b;
scanf("%I64d%I64d",&a,&b);
__int64 t = a * a - 4 * b;
if(t < 0){
puts("None");
continue;
}
__int64 p = (int)sqrt(t);
if(p * p != t){
puts("None");
}else {
if((p+a)%2==1){
puts("None");
}else{
printf("%I64d %I64d
",min((a-p)/2,(a+p)/2),max((a-p)/2,(a+p)/2));
}
}
}
return 0;
}
D题 Root
//这题不难,就是解方程,但是真的贼恶心,我想你肯定经历过好多发wa才看见A的彩虹....
#include<bits/stdc++.h>
using namespace std;
int main(){
int T;
scanf("%d",&T);
while(T--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(c==1){
if(a==b){
if(a==0)puts("1");
else puts("0");
}
else puts("None");
}else
{
if((a-c*b)==0&&b!=0) printf("0
");
else if((a-c*b)/(c-1)<0) printf("None
");
else if((a-c*b)%(c-1)==0)
{
if((a-c*b)/(c-1)==(-b)) printf("None
");
else printf("%d
",(a-c*b)/(c-1));
}
else printf("None
");
}
}
return 0;
}
E题 A+BVIII
//这题的话首先要理解因子分解,任何一个合数都是由素数乘来的。比如12 = 2^2*3而直到最小因子分解式之后就是每个素数上面的次数+1的乘积,12的话就是(2+1)*(1+1)=6不过要注意下这个数就是素数的处理。剩下的就是素数打表等知识了。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int prime[maxn];
bool primeflag[maxn];
int cnt = 0;
void Prime(){
memset(primeflag,false,sizeof(primeflag));
primeflag[1] = true;
for(int i = 2; i < 1000;i++){
if(!primeflag[i]){
for(int j = i*i;j < maxn;j+=i)primeflag[j] = true;
}
}
for(int i = 2;i < maxn;i++)if(primeflag[i] == false)prime[cnt++] = i;
//for(int i = 0;i <100;i++)printf("%d
",prime[i]);
}
int main(){
Prime();
int T;
scanf("%d",&T);
while(T--){
int a,b;
scanf("%d%d",&a,&b);
int n = a + b;
int tmp = sqrt(n) + 1;
int res = 1;
for(int i = 0; i < cnt&&prime[i] < tmp;i++){
int num = 0;
while(n % prime[i]==0){
n /= prime[i];
num++;
}
res *= (num+1);
}
if(n > 1)res *= 2;
printf("%d
",res);
}
}
F题 Score
//暴力...不过要考虑impossible的情况
#include <stdio.h>
#include <string.h>
int main()
{
int x,y;
int m,n;
char a[10] = {"Alice"},b[10] = {"Bob"},c[10],d[10] = {"Draw"};
while (scanf("%d %d",&x,&y)!=EOF)
{
getchar();
scanf("%s",c);
if ((x<y)||(((x+y)%2!=0))||((strcmp(c,d)==0)&&(x%2)!=0)||(y!=0&&strcmp(c,d)==0)||(y==0&&strcmp(c,d)!=0))
{
printf("Impossible
");
continue;
}
if (strcmp(c,d)==0) printf("%d:%d
",x/2,x/2);
else if (strcmp(c,a)==0) printf("%d:%d
",(x+y)/2,(x-y)/2);
else printf("%d:%d
",(x-y)/2,(x+y)/2);
}
return 0;
}
G题 Recetangle
//看我剧暴力的写法...
#include<bits/stdc++.h>
using namespace std;
int a[4],b[4];
int main(){
int T;
scanf("%d",&T);
int n1,m1,n2,m2,x1,y1,x2,y2;
while(T--){
scanf("%d%d%d%d",&n1,&m1,&n2,&m2);
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
a[0] = min(n1,n2);
a[1] = min(m1,m2);
a[2] = max(n1,n2);
a[3] = max(m1,m2);
b[0] = min(x1,x2);
b[1] = min(y1,y2);
b[2] = max(x1,x2);
b[3] = max(y1,y2);
int x = max(a[0],b[0]);
int y = max(a[1],b[1]);
int xx = min(a[2],b[2]);
int yy = min(a[3],b[3]);
if (x>=xx||y>=yy) printf("No
");
else printf("Yes
");
}
return 0;
}
H题 Legal Identifier
//1.判断是不是那32个 2.首字母是不是数字 3.有没有出现不是数字下划线字符的解
#include<bits/stdc++.h>
using namespace std;
char str[35][10]={"auto","break","case","char","const","continue","default","do",
"double","else","enum","extern",
"float","for","goto","if","int","long","register","return",
"short","signed","sizeof","static",
"struct","switch","typedef","union","unsigned","void","volatile",
"while"};
bool ischar(char c){
if((c>='A'&&c<='Z')||(c<='z'&&c>='a'))return true;
else if(c=='_')return true;
return false;
}
char s[50];
bool isdig(char c){
if(c>='0'&&c<='9')return true;
return false;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s",s);
bool flag = true;
//printf("%s
",s);
for(int i = 0;i < 32;i++){
if(strcmp(s,str[i])==0){
flag = false;
break;
}
}
int len = strlen(s);
for(int i = 0;i < len;i++){
if(i==0&&isdig(s[i]))flag = false;
else if(!isdig(s[i])&&!ischar(s[i]))flag = false;
}
flag?puts("Yes"):puts("No");
}
return 0;
}
I题 Matrix Transposition
//结构体排序完之后 把里面的x和y输出顺序换下即可
#include<bits/stdc++.h>
using namespace std;
struct Node{
int x,y,z;
}a[10000];
int cmp(Node c,Node d){
if(c.y==d.y)return c.x<d.x;
return c.y<d.y;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
int x,y,n;
scanf("%d%d%d",&y,&x,&n);
for(int i= 0;i < n;i++)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
sort(a,a+n,cmp);
//printf("========
");
for(int i= 0;i < n;i++)printf("%d %d %d
",a[i].y,a[i].x,a[i].z);
printf("
");
}
return 0;
}