2024-01-25竞赛笔记

2024/1/25


P1781 宇宙总统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<bits/stdc++.h>
using namespace std;
char a[10001],t[10001];//因为数字会比较大
char b[10001];
int lenx,leny,n,m=1;
int main(){
cin>>n;
cin>>a;
for(int i=1;i<n;i++){
memset(b,0,sizeof(b));//初始化
cin>>b;
lenx=strlen(a);//取数位
leny=strlen(b);
if((lenx<leny)||(lenx==leny&&strcmp(a,b)<0)){//进行交换(排序)
strcpy(t,a);
strcpy(a,b);
strcpy(b,t);
m=i+1;//序号也要一起变化
}
}
lenx=strlen(a);
cout<<m<<endl;
for(int i=0;i<lenx;i++){
cout<<a[i];
}
return 0;
}

P1059 [NOIP2006 普及组] 明明的随机数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<bits/stdc++.h>
using namespace std;
int a[114514];
signed main(){
int n,s,t=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>s;
if(a[s]) continue;//桶排序
a[s]++;
t++;
}
cout<<t<<endl;
for(int i=1;i<=1001;i++)
{
if(a[i]) cout<<i<<" ";
}
return 0;
}

P1068 [NOIP2009 普及组] 分数线划定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<bits/stdc++.h>
using namespace std;
int n,m;
struct player{
int id;
int score;
};
signed main(){
cin>>n>>m;
player a[n];//定义a[n]
for(int i=0;i<n;i++) cin>>a[i].id>>a[i].score;
for(int i=0;i<n;i++){//选择排序
int k=i;
for(int j=i+1;j<n;j++){
if(a[j].score>a[k].score) k=j;
if((a[j].score==a[k].score)&&(a[j].id<a[k].id)) k=j;
}
player temp=a[i];
a[i]=a[k];
a[k]=temp;
}
int b=m*1.5-1;//排名为m*150%的学生在数组位置下标
int line=a[b].score;//分数线
int count=0;
for(int i=0;i<n;i++){
if(a[i].score>=line) count++;
}
cout<<line<<' '<<count<<endl;
for(int i=0;i<count;i++) cout<<a[i].id<<" "<<a[i].score<<endl;
return 0;
}

P1116 车厢重组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<bits/stdc++.h>
using namespace std;
int a[10010];
int main()
{
int n,sum = 0;
cin >> n;
for(int i = 1 ; i <= n ; i ++)
cin >> a[i];
for(int i = 1 ; i <= n ; i ++)
for(int j = n ; j > 1 ; j --)
if(a[j] < a[j - 1])//冒泡排序
{
swap(a[j],a[j-1]);
sum ++;//交换次数++
}
cout << sum;
return 0;
}

P1583 魔法照片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<bits/stdc++.h>
using namespace std;
int e[114514],n,k;
struct people{
int w;//权值
int num;//编号
int d;//类别
}p[1919810];
int cmp(const people &a,const people &b){//自定义结构体排序
if(a.w!=b.w) return a.w>b.w;//从大到小
return a.num<b.num;//序号小的优先
}
signed main(){
cin>>n>>k;
for(int i=1;i<=10;i++) cin>>e[i];
for(int j=1;j<=n;j++){
cin>>p[j].w;//权值
p[j].num=j;//编号
}
sort(p+1,p+1+n,cmp);//第一次排序
for(int i=1;i<=n;i++){
p[i].d=(i-1)%10+1;//分类
p[i].w+=e[p[i].d];//加上e[i]
}
sort(p+1,p+1+n,cmp);//第二次排序
for(int i=1;i<=k;i++) cout<<p[i].num<<" ";
return 0;
}