1、新冠病毒群体免疫(covid)
直接上代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
cout<<round(n*0.75);
return 0;
}
2、整理书本(book)
考虑用结构体表示书本(包括书本编号和书本位置两个信息),每次操作只更新书本位置信息,所有操作完毕最后按位置进行排序,输出相应编号即可。 因为n、m取值范围为100000,该方法会导致超时,用链表的方法见评论区
参考代码如下:
#include<bits/stdc++.h>
using namespace std;
struct book{
int id; //编号
int order; //书本位置
}b[100005];
bool cmp(book x,book y){
return x.order<y.order;
}
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){ //初始化
b[i].id=i;
b[i].order=i;
}
while(m--){
int op,p,q,l,r;
cin>>op;
switch(op){
case 1: cin>>p;
l=b[p].order