- 赵一静 的博客
八月暑期集训8月12日DAY7题解
- @ 2024-8-12 19:31:30
糖果(数学)
思路
通过计算,我们知道:答案就在“”与“中取。所以如果与都在的某一个倍数的区间之内,就输出,否则输出。
代码
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("candy.in","r",stdin);
freopen("candy.out","w",stdout);
int n,l,r;
cin >>n>>l>>r;
if(l/n==r/n) cout <<r%n;
else cout <<n-1;
return 0;
}
排序(模拟)
待更新……
网络(模拟)
思路没想到的原因
思路很乱,虽然打了草稿,但(打了跟没打似的)思路还是很混乱。以后一定一定一定(重要的事情说三遍)草稿要认真打!!!
思路
模拟题,把类型和分开读入,更加方便以后的处理。具体步骤如下:
check函数是否返回true(这个函数等下再讲),如果不成立,输出ERR;- 如果成立,判断
mp[b]是否不等于,如果不满足,输出FAIL; - 如果满足,判断
a是等于Server还是Client。 - 若是
Server,输出OK,并且标记mp:mp[b]=i; - 若是
Client,输出mp[b]。
现在就是重中之重的check函数啦!!!
先循环存下各位的数字,且存下数位,防止存在这种样例:...:,再判断是否有前导零,如果有,返回false。
判断数位是否为空,如果不满足,存入数字栈。最后把符号存入符号栈里。
最终的最终,返回是否合法。
代码
#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
bool check(string s){
vector<int> num;
string op;
s=" "+s;
for(int i=1;i<s.size();i++){
int f=0,z=i,res=0;
while(i<s.size()&&isdigit(s[i])){
f=f*10+s[i]-'0';
i++;
res++;
if(f>65535) return false;
}
if(s[z]=='0'&&(z==1||s[z-1]=='.'||s[z-1]==':')&&(f||res>1)) return false;
if(res) num.push_back(f);
if(i>=s.size()) break;
op.push_back(s[i]);
}
return (num.size()==5&&op.size()==4&&op[0]=='.'&&op[1]=='.'&&op[2]=='.'&&op[3]==':'&&num[0]<=255&&num[1]<=255&&num[2]<=255&&num[3]<=255&&num[4]<=65535);
}
int main(){
freopen("net.in","r",stdin);
freopen("net.out","w",stdout);
int n;
cin >>n;
for(int i=1;i<=n;i++){
string a,b;
cin >>a>>b;
if(check(b)){
if((mp[b]==0&&a=="Server")||(mp[b]==0&&a=="Client")){
cout <<"FAIL"<<endl;
}else{
if(a=="Server"){
cout <<"OK"<<endl;
mp[b]=i;
}else{
cout <<mp[b]<<endl;
}
}
}else{
cout <<"ERR"<<endl;
}
}
return 0;
}
果子(数据结构)
待更新……