zoukankan      html  css  js  c++  java
  • CCF CSP 第十九次认证



    机器学习派上了用场

    #include<bits/stdc++.h>
    using namespace std;
    int getsign(long long x){
    	return x<0?-1:1;
    }
    int main(int argc, char const *argv[])
    {
    	int n;
    	int t;
    	cin>>n>>t;
    	map<char, vector<pair<long long,long long>>>  p;
    	int x,y;
    	char c;
    	for(int i=0; i<n; i++){
    		cin>>x>>y>>c;
    		p[c].push_back(make_pair(x,y));
    
    	}
    	while(t--){
    		long long a1,a2,a3;
    		cin>>a1>>a2>>a3;
    		long long A = a1+p['A'][0].first*a2+p['A'][0].second*a3;
    		long long B = a1+p['B'][0].first*a2+p['B'][0].second*a3;
    		if(getsign(A)==getsign(B)){
    			cout<<"No"<<endl;
    			continue;
    		}
    		bool flag = false;
    		for(auto pp:p['A']){
    			long long temp = a1+pp.first*a2+pp.second*a3;
    			if(getsign(temp)*getsign(A)<0){
    				flag = true;
    				break; 
    			}
    		}
    		for(auto pp:p['B']){
    			long long temp = a1+pp.first*a2+pp.second*a3;
    			if(getsign(temp)*getsign(B)<0){
    				flag = true;
    				break; 
    			}
    		}
    		if(flag)
    			cout<<"No"<<endl;
    		else
    			cout<<"Yes"<<endl;
    	}
    
    	return 0;
    }
    


    双指针

    #include<bits/stdc++.h>
    using namespace std;
    
    
    int main(int argc, char const *argv[])
    {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	int n;
    	cin>>n;
    	int a, b;
    	cin>>a>>b;
    	vector<pair<long long,long long>> X(a),Y(b);
    	long long ans = 0;
    	long long x,y;
    	for (int i = 0; i < a; ++i)
    	{
    		cin>>x>>y;
    		X[i] = make_pair(x,y);
    	}
    	for (int i = 0; i < b; ++i)
    	{
    		cin>>x>>y;
    		Y[i] = make_pair(x,y);
    	}
    	sort(X.begin(), X.end());
    	sort(Y.begin(), Y.end());
    	int i=0,j=0;
    	while(i<a&&j<b){
    		if(X[i].first==Y[j].first)
    			ans += X[i++].second* Y[j++].second;
    		else if(X[i].first<Y[j].first)
    			i++;
    		else 
    			j++;
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    




    阅读理解题,后面太麻烦了
    先骗四十分

    #include<bits/stdc++.h>
    
    using namespace std;
    
    string gets1(string s){
    	string res = "";
    	int l = 0;
    	int r = s.length()-1;
    	while(l<=r&&s[l]==' ') l++;
    	while(l<=r&&s[r]==' ') r--;
    	while(l<=r)
    		res += s[l++];
    	return res;
    }
    int main(int argc, char const *argv[])
    {
    	string s;
    	int n;
    	// freopen("test.dat","r", stdin);
    	cin>>n;
    	// getchar();
    	int ans = 0;
    	int state = 0;
    	string temp = "";
    	int len = 0;
    	while(getline(cin,s)){
    		// cout<<s;
    		string res = gets1(s);
    		if(res.length()==0){ //遇到了一个新的段落
    			if(state==0)
    				continue;
    			for(int i=0; i<temp.length(); i++){
    				if(len%n==0&&temp[i]==' ')
    					continue;
    				else{
    					len++;
    				}
    			}
    			// cout<<len<<endl;
    			ans += len/n + ((len%n)>0)+1;
    			temp = "";
    			len = 0;
    			state = 0;
    			// cout<<ans<<endl;
    		}else{
    			temp+= " "+res;
    			state = 1;
    		}
    	}
    	// cout<<len<<endl;ans += len/n + ((len%n)>0)+1;
    	if(temp.length()){
    		// if(len%n!=0)
    		// 		cout<<endl;
    			for(int i=0; i<temp.length(); i++){
    						if(len%n==0&&temp[i]==' ')
    							continue;
    						else{
    							len++;
    					}
    		}
    		ans += len/n + ((len%n)>0)+1;
    	}
    	cout<<ans-1<<endl;
    	return 0;
    }
    // 段落: 去掉每行首位的连续空格
    //		 每行开头如果是空格,那么要去掉空格
    // 		 如果有多行, 则将各行用一个空格链接起来
    //     段落与段落之间或者段落与空行之间应该空出一行间距
    
    // 项目:
    //   
    

    矩阵快速幂
    能过96分,第一次接触矩阵快速幂
    判重需要仔细考虑,两个的时候只能考虑单个数字生成
    和相邻数字生成的新的对

    #include<bits/stdc++.h>
    
    using namespace std;
    
    const long long mod = 998244353;
    
    vector<vector<long long>> se={ 
            {0,0,1,0,0,0,0,0,0,0,0,0,0,0},  
            {1,0,0,0,0,0,0,0,0,0,0,0,0,0},  
            {0,1,0,1,0,0,0,0,0,0,0,0,0,0},  
            {0,0,1,1,0,0,0,0,0,0,0,0,0,0},  
            {0,0,1,0,0,0,0,0,0,0,0,0,0,0},  
            {0,0,0,0,1,0,0,0,0,0,0,0,0,0},  
            {0,0,0,0,0,0,0,0,0,0,0,1,0,0},  
            {0,0,0,0,0,0,0,0,0,0,1,0,0,0},  
            {0,0,0,0,0,1,0,0,0,0,0,0,1,0},  
            {0,0,0,0,0,0,0,1,0,0,0,0,0,0},  
            {0,0,0,0,0,0,1,0,0,0,0,0,0,0},  
            {0,0,0,1,0,0,0,0,0,0,0,0,0,1},  
            {0,0,0,0,0,0,0,0,1,0,0,0,0,0},  
            {0,0,0,0,0,0,0,0,0,1,0,0,0,0}  
        };
    
    // vector<vector<long long>> seini = {{1,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    vector<long long> fi = {1,2,4,6,16,26,41,44,46,61,62,64,66,42};
    
    vector<vector<long long>> mmul(vector<vector<long long >> a, vector<vector<long long>> b){
    	int n = a.size();
    	int m = a[0].size();
    	int mm = b[0].size();
    	vector<vector<long long>> aa(n, vector<long long>(mm, 0LL));
    	for(int i=0; i<n; i++){
    		for(int j=0;  j<mm;j++){
    			for(int k=0; k<m; k++){
    				aa[i][j] = ((aa[i][j]%mod)+((a[i][k]%mod)*(b[k][j]%mod))%mod)%mod;
    			}
    		}
    	}
    	return aa;
    }
    vector<vector<long long>> matrix_mul(vector<vector<long long>> a, int t){
    	vector<vector<long long>> res(14, vector<long long>(14, 0LL));
    	for(int i=0; i<14; i++){
    		for(int j=0; j<14; j++){
    			res[i][j]=0;
    			if(i==j)
    				res[i][j]=1LL;
    		}
    	}
    	while(t){
    		if(t&1){
    			res = mmul(a,res);
    		}
    		a = mmul(a,a);
    		t = t>>1;
    	}
    	return res;
    }
    int main()
    {
    	int n;
    	cin>>n;
    	string s;
    	cin>>s;
    	int targ = stoi(s);
    	se = matrix_mul(se, n);
    	for(int i=0; i<14; i++){
    		if(fi[i]==targ){
    			cout<<se[i][0]<<endl;
    			return 0;
    		}
    	}
    	cout<<0<<endl;
    	return 0;
    }
    


    只会dfs暴力前四十分,但是不知道为啥只能过三十分
    离谱了,想了一天也没看出来哪里错了,随缘了

    #include<bits/stdc++.h>
    #define LL long long
    using namespace std;
    
    // 0表示不选
    // 1表示选边界
    // 2表示不选边界
    vector<vector<LL>> a(1100, vector<LL>(5,0));
    
    LL n, m;
    LL used[1100];
    LL buy[1100];
    LL ans = 0;
    vector<pair<LL,pair<LL, LL>>> sss;
    
    bool judge(){
    	for(auto ss:sss){
    		if(ss.second.second==1){
    			if(used[ss.first]&&!used[ss.second.first])
    				return false;
    		}else{
    			if(used[ss.first]==1&&!used[ss.second.first])
    				return false;
    		}
    	}
    	return true;
    }
    LL cal(){
    	LL res = 0;
    	for(LL i=1; i<=n; i++){
    		res += buy[i];
    	}
    	return res;
    
    }
    LL cal_2(LL i, LL x){
    	return a[i][2]*x*x+a[i][3]*x+a[i][4];
    }
    void dfs(LL i){
    	if(i==n+1){
    		if(judge())
    			ans = max(ans, cal());
    		// cout<<endl<<cal()<<endl;
    		return;
    	}
    	for(LL t=0; t<3; t++){
    		used[i]=t;
    		buy[i]=0;
    		if(t==1){
    			buy[i] = max(cal_2(i,a[i][0]), cal_2(i,a[i][1]));
    		}
    		else if(t==2){
    			if(a[t][2]==0){
    				buy[i]=max(cal_2(i,a[i][0]+1), cal_2(i,a[i][1]-1));
    			}else{
    				buy[i]=max(cal_2(i,a[i][0]+1), cal_2(i,a[i][1]-1));
    				LL temp = (-a[i][1]/(2LL*a[i][0]));
    				if(temp>a[i][0]&&temp<a[i][1])
    					buy[i] = max(buy[i], cal_2(i, temp));
    				temp -= 1;
    				if(temp>a[i][0]&&temp<a[i][1])
    					buy[i] = max(buy[i], cal_2(i, temp));
    				temp += 2;
    				if(temp>a[i][0]&&temp<a[i][1])
    					buy[i] = max(buy[i], cal_2(i, temp));
    			}
    		}
    		dfs(i+1);
    	}
    }
    int main()
    {
    	ans = 0;
    	memset(used,0,sizeof used);
    	memset(buy,0,sizeof buy);
    	cin>>n>>m;
    	for(LL i=1; i<=n; i++){
    		cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3]>>a[i][4];
    	}
    	LL x,y,c;
    	for(LL i=0; i<m; i++){
    		cin>>c>>x>>y;
    		sss.push_back(make_pair(x,make_pair(y,c)));
    	}
    	dfs(1);
    	cout<<ans<<endl;
    	return 0;
    }
    

    离谱的,不知道九月考试能考多少分

  • 相关阅读:
    币值转换
    第八周作业
    第七周作业
    第五周编程总结
    第四周编程总结
    第三周编程总结
    7-1 查找整数
    7-2 求最大值及其下标
    秋季学习总结
    对我影响最大的三个老师
  • 原文地址:https://www.cnblogs.com/Crossea/p/13525259.html
Copyright © 2011-2022 走看看