跳到正文

个人记录

CPS-J 9.17模拟赛

NothingIsImpossible约 7 分钟
原文

这是 2026年9月20日 存档的第 5 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年9月17日
收录
2026年9月17日
更新
2026年11月22日
篇幅
约 7 分钟

版本

  1. v8当前
  2. v7
  3. v6
  4. v5
更早的 4 个版本
  1. v4
  2. v3
  3. v2
  4. v1

A.

C++
#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int x=0, f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') {
        x=x*10+(ch-'0');
        ch=getchar();
    }
    return x*f;
}

int main(){
	freopen("hint.in","r",stdin);
	freopen("hint.out","w",stdout);
	ios::sync_with_stdio(false);
	cout.tie(0);
	int q=read(),a=read(),b=read();
	vector<int> ans;
	while(q--){
		int y=read(),m=read(),d=read();
		if(m>a){
			ans.push_back(y+1);
		}
		else{
			if(m==a and d>=b) ans.push_back(y+1);
			else ans.push_back(y);
		}
	}
	for(int n:ans) cout<<n<<endl;
	return 0;
	}


















#include<bits/stdc++.h>
using namespace std;
int main(){
	freopen("spearshield.in","r",stdin);
	freopen("spearshield.out","w",stdout);
	int n;
	cin>>n;
	string s;
	cin>>s;
	s="/"+s;
	int mi=2147483600;
	for(int i=0;i<=n;i++){
		long long jg=0,fs=0;
		for(int j=0;j<=i;j++)if(s[j]=='0') jg+=j;
		for(int j=n;j>i;j--) if(s[j]=='1') fs+=j; 
		mi=(abs(jg-fs)>mi)?mi:abs(jg-fs);
		
	}
	cout<<mi;
	return 0;
	}










#include<bits/stdc++.h>
using namespace std;
int v,g;
int need[30];
int feed[20][30];
int main(){
    cin>>v;
    for(int i=0;i<v;i++) cin>>need[i];
    cin>>g;
    for(int i=0;i<g;i++){
        for(int j=0;j<v;j++){
            cin>>feed[i][j];
        }
    }
    int cntt=INT_MAX;
    vector<int> anss;
    for(int mask=0;mask < (1<<g);mask++){
        int cnt=0;
        int sum[30]={0};
        vector<int> sel;
        for(int i=0;i<g;i++){
            if(mask & (1<<i)){
                cnt++;
                sel.push_back(i+1);
                for(int j=0;j<v;j++){
                    sum[j] += feed[i][j];
                }
            }
        }
        bool ok=true;
        for(int j=0;j<v;j++){
            if(sum[j]<need[j]){
                ok=false;
                break;
            }
        }
        if(!ok) continue;
        if(cnt < cntt){
            cntt=cnt;
            anss=sel;
        }else if(cnt == cntt){
        }
    }
    cout<<cntt;
    for(auto x:anss) cout<<" "<<x;
    cout<<endl;
    return 0;
}
#include<BITS/STDC++.H>
using namespace std;
unordered_map<string,int>mp;

bool ck(string s){
	int d=0,c=0;
	for(char ch:s){
		if(ch=='.')d++;
		if(ch==':')c++;
	}
	if(d!=3||c!=1)return 0;
	int p=s.find(':');
	string ip=s.substr(0,p),pt=s.substr(p+1);
	string t;
	long long num;
	int cnt=0;
	for(char ch:ip){
		if(ch=='.'){
			if(t.empty())return 0;
			if(t.size()>1&&t[0]=='0')return 0;
			num=stoll(t);
			if(num>255)return 0;
			t="";cnt++;
		}else t+=ch;
	}
	if(t.empty())return 0;
	if(t.size()>1&&t[0]=='0')return 0;
	num=stoll(t);
	if(num>255)return 0;
	cnt++;
	if(cnt!=4)return 0;
	t="";
	for(char ch:pt){
		t+=ch;
	}
	if(t.empty())return 0;
	if(t.size()>1&&t[0]=='0')return 0;
	num=stoll(t);
	if(num>65535)return 0;
	return 1;
}

int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		string op,ad;cin>>op>>ad;
		if(!ck(ad)){
			cout<<"ERR\n";continue;
		}
		if(op=="Server"){
			if(mp.count(ad))cout<<"FAIL\n";
			else{
				mp[ad]=i;
				cout<<"OK\n";
			}
		}else{
			if(mp.count(ad))cout<<mp[ad]<<"\n";
			else cout<<"FAIL\n";
		}
	}
	return 0;
}