• 2019中国大学生程序设计竞赛(CCPC)


    ^ & ^
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 229 Accepted Submission(s): 117

    Problem Description
    Bit operation is a common computing method in computer science ,Now we have two positive integers A and B ,Please find a positive integer C that minimize the value of the formula (A xor C) & (B xor C) .Sometimes we can find a lot of C to do this ,So you need to find the smallest C that meets the criteria .

    For example ,Let’s say A is equal to 5 and B is equal to 3 ,we can choose C=1,3… ,so the answer we’re looking for C is equal to 1.

    If the value of the expression is 0 when C=0, please print 1.

    Input
    The input file contains T test samples.(1<=T<=100)

    The first line of input file is an integer T.

    Then the T lines contains 2 positive integers, A and B, (1≤A,B<232)

    Output
    For each test case,you should output the answer and a line for each answer.

    Sample Input
    1
    3 5

    Sample Output
    1

    纪念一下我的傻逼脑子,这个题目肯定是将两个位都是1的消掉,也就是同时异或上a&b ,但是我当时没想到会超int。日,,,wa了多少,还是队友写对的,我真想撞死算了,以后直接longlong,,,,

    #include <iostream>
    using namespace std;
    typedef long long ll ;
    int main()
    {
    	int t ;
    	cin >> t ;
    	while(t --)
    	{
    		ll n , m ;
    		cin >> n >> m ;
    		n = 1ll * n & m ;
    		if(n == 0) n = 1 ; 
    		cout << n << endl ;
    	}
    	return 0 ;
    }
    

    Fishing Master

    Problem Description
    Heard that eom is a fishing MASTER, you want to acknowledge him as your mentor. As everybody knows, if you want to be a MASTER’s apprentice, you should pass the trial. So when you find fishing MASTER eom, the trial is as follow:

    There are n fish in the pool. For the i - th fish, it takes at least ti minutes to stew(overcook is acceptable). To simplify this problem, the time spent catching a fish is k minutes. You can catch fish one at a time and because there is only one pot, only one fish can be stewed in the pot at a time. While you are catching a fish, you can not put a raw fish you have caught into the pot, that means if you begin to catch a fish, you can’t stop until after k minutes; when you are not catching fish, you can take a cooked fish (stewed for no less than ti) out of the pot or put a raw fish into the pot, these two operations take no time. Note that if the fish stewed in the pot is not stewed for enough time, you cannot take it out, but you can go to catch another fish or just wait for a while doing nothing until it is sufficiently stewed.

    Now eom wants you to catch and stew all the fish as soon as possible (you definitely know that a fish can be eaten only after sufficiently stewed), so that he can have a satisfying meal. If you can complete that in the shortest possible time, eom will accept you as his apprentice and say “I am done! I am full!”. If you can’t, eom will not accept you and say “You are done! You are fool!”.

    So what’s the shortest time to pass the trial if you arrange the time optimally?

    Input
    The first line of input consists of a single integer T(1≤T≤20), denoting the number of test cases.

    For each test case, the first line contains two integers n(1≤n≤105),k(1≤k≤109), denoting the number of fish in the pool and the time needed to catch a fish.

    the second line contains n integers, t1,t2,…,tn(1≤ti≤109) ,denoting the least time needed to cook the i - th fish.

    Output
    For each test case, print a single integer in one line, denoting the shortest time to pass the trial.

    Sample Input
    2
    3 5
    5 5 8
    2 4
    3 3

    Sample Output
    23
    11

    Hint

    Case 1: Catch the 3rd fish (5 mins), put the 3rd fish in, catch the 1st fish (5 mins), wait (3 mins),

    take the 3rd fish out, put the 1st fish in, catch the 2nd fish(5 mins),

    take the 1st fish out, put the 2nd fish in, wait (5 mins), take the 2nd fish out.

    Case 2: Catch the 1st fish (4 mins), put the 1st fish in, catch the 2nd fish (4 mins),

    take the 1st fish out, put the 2nd fish in, wait (3 mins), take the 2nd fish out.

    这个题目我知道是用贪心做,但是不管怎么想都是错的,根本原因是我没想到可以不止捕一条鱼,我以为在煮鱼的同时只能补一条,也就是即使剩下可以再捕几条鱼的时间也只能捕一条,然后就一直wawawawa的哭啊,
    抓第一条鱼的耗时是无法避免的,抓鱼应该从烹饪时间最长的开始抓起,这样才可以用烹饪时间去抓更多的鱼,而剩下的不够抓一条鱼的烹饪时间应该存下来,后面在抓鱼的时候从这些时间中选出最大的x,抓鱼的时间会和烹饪的时间重合最多,这样可以使时间(k-x)最小。

    #include <iostream>
    #include <queue>
    #include <algorithm>
    using namespace std;
    typedef long long ll ;
    priority_queue<int> q ;
    const int N = 1e5 + 10 ;
    int a[N] ;
    bool cmp(int a,  int b)
    {
    	return a > b ;
    }
    int main()
    {
    	int T ;
    	scanf("%d",&T) ;
    	while(T --)
    	{
    		while(q.size()) q.pop() ;
    		int n , k ;
    		scanf("%d%d",&n,&k) ;
    		for(int i = 1;i <= n;i ++)
    		 scanf("%d" , &a[i]) ;
    		sort(a + 1 ,  a + n + 1 , cmp) ;
    		ll ans = k + a[1] ;
    		int t = a[1] / k ;
    		if(a[1] % k) 
    		 q.push(a[1] % k) ;
    	    int i ;
    		for(i = 2;i <= n;i ++)
    		 {
    		 	if(t)
    		 	 {
    		 	 	t -- ;
    		 	 	t += a[i] / k;
    		 	 	ans += a[i] ;
    		 	 	if(a[i] % k)
    		 	 	 q.push(a[i] % k) ;
    		 	 	 
    			 }
    			 else 
    			   break ;
    		 }
    		 for(;i <= n;i ++)
    		  {
    		  	int x = q.top() ;
    		  	q.pop() ;
    		  	ans += k - x + a[i] ;
    		  	q.push(a[i]) ;
    		  }
    		 cout << ans << endl ;
    	} 
    	
    	return 0 ;
    } 
    

    Windows Of CCPC
    Problem Description
    In recent years, CCPC has developed rapidly and gained a large number of competitors .One contestant designed a design called CCPC Windows .The 1-st order CCPC window is shown in the figure:

    And the 2-nd order CCPC window is shown in the figure:

    We can easily find that the window of CCPC of order k is generated by taking the window of CCPC of order k−1 as C of order k, and the result of inverting C/P in the window of CCPC of order k−1 as P of order k.
    And now I have an order k ,please output k-order CCPC Windows , The CCPC window of order k is a 2k∗2k matrix.

    Input
    The input file contains T test samples.(1<=T<=10)

    The first line of input file is an integer T.

    Then the T lines contains a positive integers k , (1≤k≤10)

    Output
    For each test case,you should output the answer .

    Sample Input
    3
    1
    2
    3

    Sample Output
    CC
    PC
    CCCC
    PCPC
    PPCC
    CPPC
    CCCCCCCC
    PCPCPCPC
    PPCCPPCC
    CPPCCPPC
    PPPPCCCC
    CPCPPCPC
    CCPPPPCC
    PCCPCPPC

    在这里插入图片描述

    一共要输出2^n行,那么可以一行一行的输出,假设我要输出总行为8行,现在要输出第1行,
    那么其实是输出总行为4行的第1行输出两遍,
    当输出左下角的部分时,这是总行为4行的相应行相反输出1遍,在输出1遍相同的。

    #include <iostream>
    #include <algorithm>
    #include <cmath> 
    using namespace std;
    void f(int n , int s , int t)
    {
    	if(n == 2)
    	 {
    	 	if(t == 1) 
    	 	 {
    	 	 	if(s == 1) cout << "CC" ;
    	 	 	else cout << "PC" ;
    		 }
    		 else 
    		  {
    		  	if(s == 1) cout << "PP" ;
    		  	else  cout << "CP" ;
    		  }
    		  return ;
    	 }
    	 int x = s % (n / 2) ;
    	 if(x == 0) x = n / 2 ;
    	 if(t == 1)
    	  {
    	  	if(s > n / 2) f(n / 2 , x , 0) ;
    	  	else f(n / 2 , x , 1) ;
    	  	f(n / 2 , x , 1) ;
    	  }
    	  else if(t == 0)
    	   {
    	   	if(s > n / 2)
    	   	   f(n / 2 , x , 1) ;
    	   	else f(n / 2 , x , 0) ;
    	   	f(n / 2 , x , 0) ;
    	   }
    }
    int main()
    {
    	int n , t ;
    	scanf("%d",&t) ;
    	while(t --)
    	{
    		int n ;
    		scanf("%d" , &n) ;
    		n = pow(2 , n) ;
    		for(int i = 1;i <= n;i ++)
    		 {
    		 	f(n , i , 1) ;
    		 	puts("") ;
    		 }
    	}
    	return 0 ;
    }
    

    Shuffle Card
    Problem Description
    A deck of card consists of n cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to n. We complete the shuffle process in the following way, In each operation, we will draw a card and put it in the position of the first card, and repeat this operation for m times.

    Please output the order of cards after m operations.

    Input
    The first line of input contains two positive integers n and m.(1<=n,m<=105)

    The second line of the input file has n Numbers, a sequence of 1 through n.

    Next there are m rows, each of which has a positive integer si, representing the card number extracted by the i-th operation.

    Output
    Please output the order of cards after m operations. (There should be one space after each number.)

    Sample Input
    5 3
    1 2 3 4 5
    3
    4
    3

    Sample Output
    3 4 1 2 5

    这个题目说是把每一次操作的牌都放第一位,我踏马,,,,,看错了,这个样例设置的也是够绝,让自己误以为自己写的没错啊,然后直接甩给队友,让他刷水题,一次就AC了 ,,,,

    #include <iostream>
    using namespace std;
    const int N = 1e5 + 10 ;
    int a[N] , vis[N] , b[N] , tot , d[N];
    int main()
    {
    	int n , m ;
    	scanf("%d%d",&n,&m);
    	for(int i = 1;i <= n;i ++)
    	 scanf("%d",&a[i]) ;
    	for(int i = 1;i <= m;i ++)
    		scanf("%d",&d[i]) ;
    	for(int i = m;i >= 1;i --)
    	 if(!vis[d[i]])
    	  b[++ tot] = d[i] , vis[d[i]] = 1  ;
    	for(int i = 1;i <= n;i ++)
    	 if(!vis[a[i]])
    	  b[++ tot] = a[i] ;
    	for(int i = 1;i <= tot ;i ++)
    	 printf("%d " , b[i]) ;
    	return 0 ;
    }
    

    上面的四题都是水题,但是我全部栽上面了 , 打死
    待续

    每次做题提醒自己:题目到底有没有读懂,有没有分析彻底、算法够不够贪心、暴力够不够优雅。
  • 相关阅读:
    idea jsp无法加载<c:foreach>循环遍历数据
    java POI读取Excel文件
    Javaweb中请求的资源[/Servlet]不可用解决方案
    大作业第一阶段冲刺(一)
    hive中sql左外连接查询列值为null
    关于ECharts在jsp页面无法显示的问题
    echarts通过ajax实现数据加载
    读书笔记
    解决:[Err] 1064
    idea启动Tomcat报错Artifact testdemo1:war exploded: Error during artifact deployment. See server log for details.问题解决
  • 原文地址:https://www.cnblogs.com/spnooyseed/p/12870917.html
Copyright © 2020-2023  润新知