Bootstrap

第11次CCF CSP认证真题解

1、打酱油

题目链接:https://sim.csp.thusaac.com/contest/11/problem/0

本题只需推导出所有输出样例都满足的规律式并输出即可。

100代码:

#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	
	printf("%d\n", n / 50 * (5 + 2) + n % 50 / 30 * (3 + 1) + (n - 50 * (n / 50) - n % 50 / 30 * 30) / 10);
	
	return 0;
}

评测结果:

2、公共钥匙盒

题目链接:https://sim.csp.thusaac.com/contest/11/problem/1

根据自己的暴力法思路写了一波,结果超时了,只有70分。

70分代码:

#include <iostream>
#include <algorithm> 
using namespace std;
int main(int argc, char *argv[])
{
	int N,K;
	cin >> N >> K;
	
	int w[1010],s[1010],c[1010];
	int time[2010];
	for(int i = 1; i <= K; i++){
	    cin >> w[i] >> s[i] >> c[i];
		time[i] = s[i];	
	}
	int a[1010];
	for(int i = 1; i <= N; i++){
	    a[i] = i;	
	}
	
	int t = K+1;
	for(int i = 1; i <= K; i++){
	    time[t] = s[i]+c[i];
		t++;	
	}
	
	for(int i = 1; i <= 2*K; i++){  
		int ans1 = 10110;     
		for(int j = 1; j <= 2*K; j++){
		    ans1 = min(ans1 , time[j]);
	    }
	    for(int j = 1; j <= 2*K; j++){
    		if(time[j] == ans1 && j > K && j <= 2*K){
   			   int count1 = 0;
   			   for(int u = K+1; u <= 2*K; u++){
   			   	   if(time[u] == ans1)count1++;
   			   }
   			   if(count1 == 0){
   			   	  for(int t = 1; t <= N; t++){
  	   			   	  if(a[t] == w[j-K]){
  	   			   	  	 a[t] = 0;
  	   			   	  	 time[j] = 10110;
  	   			   	  }
  	   			   }
   			   }
   			   else if(count1 > 0){
   			   	   for(int x = 1; x <= count1; x++){
   			   	       int ans2 = 10110; 
   			   	       for(int v = K+1; v <= 2*K; v++){
	    				   if(time[v] == ans1)ans2 = min(ans2 , w[v-K]);	
   			   	       }
			    		   for(int w = 1; w <= N; w++){
   		    			       if(a[w] == 0){
       			    		   	  a[w] = ans2;
       			    		   	  break;
       			    		   }
   		    			   }
                           for(int z = K+1; z <= 2*K; z++){
                           	   if(w[z-K] == ans2 && time[z] == ans1){
		    			          time[z] = 10110;
   		    			          w[z-K] = 10110;
   		    			          break;
   	                           }
                           } 
	    	         }
   			    }
	        }   
		    
		    else if(time[j] == ans1 && j <= K){
		    	int count2 = 0;
    			for(int u = K+1; u <= 2*K; u++){
			    	if(time[u] == ans1)count2++;
			    }
			    if(count2 == 0){
   				   for(int t = 1; t <= N; t++){
   				   	   if(a[t] == w[j]){
   	   				   	  a[t] = 0;
   	   				   	  time[j] = 10110;
   	   				   }
   				   }
    			}
    			
    			else if(count2 > 0){
    				for(int x = 1; x <= count2; x++){
    				    int ans2 = 10110; 
			    	    for(int v = K+1; v <= 2*K; v++){
	    				    if(time[v] == ans1)ans2 = min(ans2 , w[v-K]);
			    	    }
			    		       for(int w = 1; w <= N; w++){
   		    			           if(a[w] == 0){
           			    		   	  a[w] = ans2;
           			    		   	  break;
           			    		   }
   		    			       }
   		    			      for(int z = K+1; z <= 2*K; z++){
                           	      if(w[z-K] == ans2 && time[z] == ans1){
		    			             time[z] = 10110;
   		    			             w[z-K] = 10110;
   		    			             break;
   	                              }
                              }  
	    			     }   
			        }
   			    }
    		}
       }
	
	   for(int i = 1; i <= N; i++){
           cout << a[i] << " ";
       }
       cout << endl;
	
	return 0;
}

评测结果:

;