7月25日比赛总结
T1
用一个桶统计报名课程的数量,如果是 就进行统计。
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, a[N], b[N], vis[N], cnt;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
vis[a[i]]++;//桶存
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
vis[b[i]]++;
}
for (int i = 1; i <= N; i++)
if (vis[i] == 2)
cnt++;//统计
cout << cnt;
return 0;
}
T2
对于每一组数据,用分支结构判断即可,题目有下限 ,所以把分和 取最大值即为分数。
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--){
int a, p;
cin >> a >> p;
if (p < 16) a = max(0, a - 10);
if (p > 20) a = max(0, a - p + 20);//比较,防止为0
cout << a << '\n';//\n比endl快
}
return 0;
}
T3
根据勾股定理,枚举第 条边,用 求出第二条直角边,再判断 即可。
#include <bits/stdc++.h>
using namespace std;
double c;
int a, b;
int main() {
cin >> c;
for (int i = 1; i <= c; i++){
int a = sqrt(c * c - i * i); //底边
if (i * i + a * a == c * c) { //判断
cout << i << " " << a; //统计
return 0;//i正序枚举,对应a一定最小
}
}
return 0;
}
T4
每次输入时顺便统计最大最小值即可。因为输入量大,要使用 或关闭流同步。
#include<cstdio>
#include<climits>
using namespace std;
int a[1000005],n;
double minn=INT_MAX,maxx=INT_MIN,s;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
s=s+a[i];
if(a[i]>maxx) maxx=a[i];
if(a[i]<minn) minn=a[i];//最大最小值
if(i>=3) printf("%.2f\n",(s-minn-maxx)/(i-2));//求平均数
}
return 0;
}
T5
这是一道结论题。
首先异或就是两个数的相同二进制位相同取 ,不同取 。
而异或结果等于 ,说明末尾一个是 ,一个是 。
末尾是 ,偶数,想到唯一的偶质数 ,是第一个质数。
另一个就是 。
#include<bits/stdc++.h>
using namespace std;
int t,a,b;
int main(){
cin>>t;
while(t--){//多组数据
cin>>a>>b;
if((a==2&&b==1)||(a==1&&b==2)) puts("Yes");//判断 2 和 3
else puts("No");
}
}
T6
观察一下数据范围就会发现,数的范围只有600,想到了桶排。
用桶存一下,最后判断 中最高的可行的 输出即可。
#include<bits/stdc++.h>
using namespace std;
const int N=605;
int a[N],n,w,x,sum;
int main(){
cin>>n>>w;
for(int i=1;i<=n;i++){
cin>>x;
a[x]++;//桶
sum=0;
for(int j=600;j>=0;j--){
sum+=a[j];
if(sum>=max(1,i*w/100)){//过线
cout<<j<<' ';//输出
break;
}
}
}
return 0;
}