20260823总结(来追梦)
考试情况
| 题目 | 分数 |
|---|---|
| T1 | 30 |
| T2 | 0 |
| T3 | 5 |
| T4 | 0 |
T1
错误思路:直接骗分
错误代码:```
#include<bits/stdc++.h>
using namespace std;
int a,b;
int sum;
int main(){
// cin>>a>>b;
// for(int i=a;i<=b;i++){
// int a[10]={0};
// int b[10]={0};
// int x=i;
// int A=1;
// int B=8;
// int e=8;
// while(e--){
// a[A]=x%10;
// A++;
// b[B]=x%10;
// B--;
// x/=10;
// }
// bool f=0;
// for(int i=1;i<=8;i++){
// if(a[i]!=b[i]){
// f=1;
// break;
// }
// }
// if(f==0)sum++;
// }
// cout<<sum;
cout<<0;
return 0;
}
//20110101
//
//20111231
正确思路:枚举月日,拼接生成回文日期,判断是否在输入区间内,统计符合条件的总数。
正确代码:
#include<bits/stdc++.h>
using namespace std;
int day[15]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
int d1,d2,ans=0;
cin>>d1>>d2;
int dd=1,mm=1;
while(mm<=12){
int d=dd%10*10000000+dd/10*1000000+mm%10*100000+mm/10*10000+mm*100+dd;
if(d>=d1&&d<=d2)ans++;
dd++;
if(dd>day[mm])dd=1,mm++;
}
cout<<ans;
return 0;
}
T2
错误思路:用了f[]来标记用没用过,并且没有记录hh,导致超时
错误代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+6;
int n;
struct node{
int q,t;
}a[N];
int sum;
int cnt;
int u,q,t;
bool f[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>u>>q>>t;
if(u==0){
a[++cnt].q=q;
a[++cnt].t=t;
sum+=q;
}else{
bool fl=0;
for(int j=1;j<=cnt;j++){
if(a[j].q>=q&&t-a[j].t<=45&&f[j]==0){
fl=1;
f[j]=1;
break;
}
}
if(fl==0){
sum+=q;
}
}
}
cout<<sum;
return 0;
}
正确思路:用一个tt和hh来记录,这样就不用f[]了
正确代码:
#include<bits/stdc++.h>
using namespace std;
struct node{
int t,p;
}a[100005];
int n;
int ans;
int hh=1,tt=1;
int main(){
cin>>n;
while(n--){
int op,t,p;
cin>>op>>p>>t;
bool f=0;
if(op==0){
tt++;
a[tt].t=t;
a[tt].p=p;
ans+=p;
tt++;
}else{
while(hh<tt&&t-a[hh].t>45)hh++;
for(int i=hh;i<tt;i++){
if(a[i].p>=p&&t-a[i].t<=45){
a[i].p=0;
f=1;
break;
}
}
if(f==0)ans+=p;
}
}
cout<<ans;
return 0;
}
T3
错误思路:模拟错了
错误代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
string t;
int a,b,c,d,e;
char A,B,C,D;
string s[1005];
int ans[1005];
int cnt;
signed main(){
cin>>n;
for(int k=1;k<=n;k++){
cin>>t;
if(t=="Server"){
cin>>a>>A>>b>>B>>c>>C>>d>>D>>e;
if(a>255||b>255||c>255||d>255||A!='.'||B!='.'||C!='.'||D!=':'||e>65525){
cout<<"ERR"<<'\n';
continue;
}
if(a<1||b<1||c<1||d<1||e<1){
cout<<"ERR"<<'\n';
continue;
}
string w;
w+=a+'0';
w+=A;
w+=b+'0';
w+=B;
w+=c+'0';
w+=C;
w+=d+'0';
w+=D;
w+=e+'0';
bool f=0;
for(int i=1;i<=cnt;i++){
if(s[i]==w){
cout<<"FAIL"<<'\n';
f=1;
break;
}
}
if(f==0){
s[++cnt]=w;
cout<<"OK"<<'\n';
ans[cnt]=k;
}
}else{
cin>>a>>A>>b>>B>>c>>C>>d>>D>>e;
if(a>255||b>255||c>255||d>255||A!='.'||B!='.'||C!='.'||D!=':'||e>65525){
cout<<"ERR"<<'\n';
continue;
}
if(a<1||b<1||c<1||d<1||e<1){
cout<<"ERR"<<'\n';
continue;
}
string w;
w+=a+'0';
w+=A;
w+=b+'0';
w+=B;
w+=c+'0';
w+=C;
w+=d+'0';
w+=D;
w+=e+'0';
bool f=0;
for(int i=1;i<=cnt;i++){
if(s[i]==w){
cout<<ans[i]<<'\n';
f=1;
break;
}
}
if(f==0){
cout<<"FAIL"<<'\n';
}
}
}
return 0;
}
正确思路:搞一个函数来判断这个地址合不合法
正确代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<string,int> mp;
int f(string s){
s+='@';
int num=0;
int cnt=0;
int cnt1=0;
string ss;
for(int i=0;i<s.size();i++){
if(s[i]=='.'){
cnt++;
//if(ss.size()==0)return 1;
if(ss.size()==0||num<0||num>255||to_string(num)!=ss){
//cout<<"______";
return 1;
}
num=0;
ss="";
}else if(s[i]==':'){
cnt1++;
if(cnt<3||cnt1>1||ss.size()==0||num<0||num>255||to_string(num)!=ss){
return 1;
}
num=0;
ss="";
}else if(s[i]=='@'){
if(ss.size()==0||num<0||num>65535|to_string(num)!=ss){
return 1;
}
num=0;
ss="";
}else{
ss+=s[i];
num=num*10+(s[i]-'0');
}
}
if(cnt!=3||cnt1!=1){
return 1;
}
return 0;
}
signed main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
string op,s;
cin>>op>>s;
if(op=="Server"){```
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int n;
cin>>n;
while(n--){
int a,b,c;
cin>>a>>b>>c;
int q,p;
bool f=0;
for(int i=1;i<=a*b*c;i++){
for(int j=1;j<=a*b*c;j++){
if(a==i*j&&b*c==(i-1)*(j-1)+1){
q=i;
p=j;
f=1;
break;
}
}
}
if(f==1){
cout<<q<<' '<<p<<'\n';
}else{
cout<<"NO"<<'\n';
}
}
return 0;
}
//10
//770 77 5
//633 1 211
//545 1 499
//683 3 227
//858 3 257
//723 37 13
//572 26 11
//867 17 17
//829 3 263
//528 4 109
if(f(s)==1){
cout<<"ERR"<<'\n';
continue;
}
if(mp.count(s)==0){
mp[s]=i;
cout<<"OK";
cout<<'\n';
}else{
cout<<"FAIL"<<'\n';
}
}else{
if(f(s)){
cout<<"ERR"<<'\n';
continue;
}
if(mp.count(s)==0){
cout<<"FAIL"<<'\n';
}else{
cout<<mp[s]<<'\n';
}
}
}
return 0;
}
T4
错误思路:没思路所以直接暴力搜索了
错误代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int n;
cin>>n;
while(n--){
int a,b,c;
cin>>a>>b>>c;
int q,p;
bool f=0;
for(int i=1;i<=a*b*c;i++){
for(int j=1;j<=a*b*c;j++){
if(a==i*j&&b*c==(i-1)*(j-1)+1){
q=i;
p=j;
f=1;
break;
}
}
}
if(f==1){
cout<<q<<' '<<p<<'\n';
}else{
cout<<"NO"<<'\n';
}
}
return 0;
}
//10
//770 77 5
//633 1 211
//545 1 499
//683 3 227
//858 3 257
//723 37 13
//572 26 11
//867 17 17
//829 3 263
//528 4 109