- chenshixian 的博客
陈室先的总结8.12day8
- @ 2024-8-12 20:03:16
题目传送门
T1糖果
思路
if 和r在一个x*n+y(余数)r%n最优 else n-1最优
代码
#include<bits/stdc++.h>
using namespace std;
long long n,l,r,ma=-100;
int main(){
freopen("candy.in","r",stdin);
freopen("candy.out","w",stdout);
cin>>n>>l>>r;
if(r%n!=n-1){
int x=r%n;
r-=x;
r--;
if(r<l)cout<<(r+x+1)%n;
else cout<<r%n;
}
else cout<<r%n;
return 0;
}
T3网络
思路
看起来难,其实还行
可以分两种情况
- 为服务机,那么要判断是否合法和是否重复创建,都没有要记录编号
- 为客户机,那么要判断是否合法和是存在对应服务机,都没有要输出对应服务机编号
判断是否合法
- 有没有出现. . . . : 类似的情况
- 有没有 0.0.0.0:-1 类似的情况
- 有没有 0.0.0.0:99999 类似的情况
- 有没有 0.0.0.999:0 类似的情况
- 有没有 0.0.0.0:00 类似的情况
代码
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,int>m;
bool ch(string a){
vector<int>c(5,-1);
sscanf(a.c_str(),"%d.%d.%d.%d:%d",&c[0],&c[1],&c[2],&c[3],&c[4]);
for(int i=0;i<5;i++){
if(c[i]<0)return 0;
if(i<=3)if(c[i]>255)return 0;
if(i==4)if(c[i]>65535)return 0;
}
char aa[100];
sprintf(aa,"%d.%d.%d.%d:%d",c[0],c[1],c[2],c[3],c[4]);
return aa==a;
}
int main(){
freopen("net.in","r",stdin);
freopen("net.out","w",stdout);
int q;
cin>>q;
for(int i=1;i<=q;i++){
string l,h;
cin>>l>>h;
if(l=="Server"){
if(!ch(h))cout<<"ERR";
else if(m[h])cout<<"FAIL";
else{
cout<<"OK";
m[h]=i;
}
}
else{
if(!ch(h))cout<<"ERR";
else if(!m[h])cout<<"FAIL";
else cout<<m[h];
}
cout<<"\n";
}
return 0;
}
错误与感想
在考试是代码写得过于复杂,考虑都没考虑全创下55分的全班唯一记录
以后思路要整理好一点,打草稿,争取把这种题AC,不丢冤枉分