题面:
代码:
candy:
数学方法,时间复杂度为常数,100
p
t
s
pts
pts
代码:
#include<bits/stdc++.h>
using namespace std;
int n,l,r;
int main(){
freopen("candy.in","r",stdin);
freopen("candy.out","w",stdout);
scanf("%d%d%d",&n,&l,&r);
int k=l/n;
int n0=n;
n=n*k;
if(r-n>=n0)printf("%d",n0-1);
else printf("%d",r-n);
return 0;
}
sort:
绞尽脑汁为正解,结果不知哪里WA了,只有8
p
t
s
pts
pts,不要太贪。
代码:
#include<bits/stdc++.h>
using namespace std;
int n,q;
struct p{
int id,num;
}a[8030];
int pl[8030],fpl[8030];
int opt,x,v;
bool cmp(p c,p b){
if(c.num!=b.num)
return c.num<b.num;
else
return c.id<b.id;
}
void insertion_sort(int v){
while(!cmp(a[v],a[v+1])){
swap(a[v],a[v+1]);
++v;
}
while(!cmp(a[v-1],a[v])){
swap(a[v-1],a[v]);
--v;
}
}
int main(){
freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i){
scanf("%d",&a[i].num);
a[i].id=i;
}
a[0].id=0;
a[0].num=-1;
a[n+1].id=n+1;
a[n+1].num=1e9+10;
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;++i){
pl[a[i].id]=i;
fpl[i]=a[i].id;
}
for(int i=1;i<=q;i++){
scanf("%d",&opt);
if(opt==1){
scanf("%d%d",&x,&v);
a[fpl[x]].num=v;
insertion_sort(fpl[x]);
for(int j=1;j<=n;j++){
pl[a[j].id]=j;
fpl[j]=a[j].id;
}
}
else{
scanf("%d",&x);
printf("%d\n",pl[x]);
}
}
return 0;
}
network:
我应该能AC,但75
p
t
s
pts
pts,可能判ERR有什么问题。
代码:
#include<bits/stdc++.h>
using namespace std;
int n;
string s1[1005],s2[1005],opt;
map<string,int> num;
bool check(string x){
int len=x.length();
int p=0;
long long num;
for(int j=1;j<=4;j++){
num=0;
while(isdigit(x[p])){
if(num==0&&x[p]==48&&p+1<len&&isdigit(x[p+1]))return false;
num+=x[p]-48;
if(num>255)return false;
num*=10;
++p;
}
if(j==4&&x[p]!=':')return false;
if(j<4&&x[p]!='.')return false;
++p;
}
num=0;
while(isdigit(x[p])){
if(num==0&&x[p]==48&&p+1<len&&isdigit(x[p+1]))return false;
num+=x[p]-48;
if(num>65535)return false;
num*=10;
++p;
if(p==len)return true;
}
return false;
}
int main(){
freopen("network.in","r",stdin);
freopen("network.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;++i){
cin>>opt;
if(opt=="Server"){
cin>>s1[i];
if(!check(s1[i]))puts("ERR");
else if(num[s1[i]])puts("FAIL");
else{
puts("OK");
num[s1[i]]=i;
}
}
else{
cin>>s2[i];
if(!check(s2[i]))puts("ERR");
else if(num[s2[i]])printf("%d\n",num[s2[i]]);
else puts("FAIL");
}
}
return 0;
}
fruit:
较为暴力,70
p
t
s
pts
pts,应该用链表,但没实现。
代码:
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
bool vis[200005];
int main(){
//freopen("fruit.in","r",stdin);
//freopen("fruit.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
int left=n;
while(left>0){
int last=-1;
for(int i=1;i<=n;i++){
if(vis[i])continue;
if(a[i]!=last){
last=a[i];
printf("%d ",i);
vis[i]=true;
left--;
}
}
puts("");
}
return 0;
}
总结:
100+8+75+70=253,一般一般,太菜了,国一悬了。
再见!普及组生涯结束!