#include<iostream>#include<cstring>#include<algorithm>#include<set>#definexfirst#defineysecondusingnamespace std;constint N =1010;typedef pair<longdouble,longdouble> PDD;typedeflonglong LL;
LL ans;
PDD p;longdouble s[N][2];bool st[N];intmain(){int n;
cin >> n;for(int i =0; i < n; i ++){
cin >> s[i][0]>> s[i][1];
set<PDD> S;for(int j =0; j < i; j ++){if(st[j])continue;if(s[i][0]== s[j][0]){if(s[i][1]== s[j][1]){
st[i]=true;break;}elsecontinue;}
p.x =(s[j][1]- s[i][1])/(s[i][0]- s[j][0]);
p.y = s[i][0]* p.x + s[i][1];
S.insert(p);}if(!st[i]) ans += S.size()+1;}
cout << ans +1<< endl;return0;}
成绩分析
#include<iostream>usingnamespace std;intmain(){// 请在此输入您的代码int minn =110, maxn =-1;double avg;double n, sum =0;
cin >> n;for(int i =0; i < n; i ++){int x;
cin >> x;
minn =min(minn, x);
maxn =max(maxn, x);
sum += x;}
avg = sum / n;printf("%d\n%d\n%.2lf", maxn, minn, avg);return0;}
B组
路径
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =2200;int g[N][N];int dist[N];int n =2021;bool st[N];intgcd(int a,int b){return b ?gcd(b, a % b): a;}voiddijkstra(){memset(dist,0x3f,sizeof dist);
dist[1]=0;for(int i =1; i <= n; i ++){int t =-1;for(int j =1; j <= n; j ++)if(!st[j]&&(t ==-1|| dist[j]< dist[t]))
t = j;
st[t]=true;for(int j =1; j <= n; j ++)
dist[j]=min(dist[j], dist[t]+ g[t][j]);}}intmain(){memset(g,0x3f,sizeof g);for(int i =1; i <=2021; i ++)for(int j =max(i -21,1); j <=min(i +21, n); j ++){int d =gcd(i, j);
g[i][j]= g[j][i]= i * j / d;}dijkstra();
cout << dist[n]<< endl;return0;}
时间显示
#include<iostream>#include<cstring>#include<algorithm>typedeflonglong LL;usingnamespace std;intmain(){
LL n, h, m, s;
cin >> n;
n /=1000;
h = n /3600%24;
n %=3600;
s = n %60;
m = n /60;printf("%02lld:%02lld:%02lld", h, m, s);return0;}
C组
快速排序
#include<bits/stdc++.h>usingnamespace std;intquick_select(int a[],int l,int r,int k){int p =rand()%(r - l +1)+ l;int x = a[p];{int t = a[p]; a[p]= a[r]; a[r]= t;}int i = l, j = r;while(i < j){while(i < j && a[i]< x) i++;if(i < j){
a[j]= a[i];
j--;}while(i < j && a[j]> x) j--;if(i < j){
a[i]= a[j];
i++;}}
a[i]= x;
p = i;if(i - l +1== k)return a[i];if(i - l +1< k)returnquick_select( a, i, r, k );//填空 //通过观察对比else的quick_select参数可直接写出结果elsereturnquick_select(a, l, i -1, k);}intmain(){int a[100];int n;
cin>>n;for(int i=0;i<n;i++)
cin>>a[i];
cout<<quick_select(a,0, n-1,5);return0;}
凑算式
#include<bits/stdc++.h>usingnamespace std;int a[]={1,2,3,4,5,6,7,8,9};intmain(){// 请在此输入您的代码longlong ans =0;sort(a, a +9);do{if(a[0]+(a[1]*1.0/ a[2])+(a[3]*100+ a[4]*10+ a[5])*1.0/(a[6]*100+ a[7]*10+ a[8])==10){
ans ++;}}while(next_permutation(a , a +9));
cout <<ans << endl;return0;}