Tc srm 549 div2

Source: Internet
Author: User

Reprint please indicate the source, thank you http://blog.csdn.net/ACM_cxlove? Viewmode = contents by --- cxlove

 

The first TC did not blow 0, but it was still short. Ah, TC's questions are too long and there are obstacles to understanding.

250pt: There are three hats, one of which has a ball. Each time, two adjacent hats are exchanged randomly. After N exchanges (here n is the number of times the two hats are exchanged, including the number of balls), where is the most likely position of the ball.

Because if it is at bits, one exchange can only be at 1 bits, and if it is at 1 bits, one exchange, bits, and other probabilities, but smaller bits are 0 bits. This can be determined based on the initial position and parity.

class BallAndHats{public:int getHat(string hats, int numSwaps){int pos;for(int i=0;i<3;i++)if(hats[i]=='o')pos=i;if(numSwaps==0)return pos;if(pos==0){if(numSwaps&1)return 1;elsereturn 0;}if(pos==1){if(numSwaps&1)return 0;elsereturn 1;}else{if(numSwaps&1)return 1;elsereturn 0;}}};

500pt: it takes a lot of time to read the question. The condition that the two cones can form a XXX is that the lower cone must expose a part, and the upper cone is higher than the lower one.

The first condition is that the radius of the cone above is smaller than that below.

The latter condition is that the slope of the slope must be large.

Then there is a naked Binary Graph Match, And the write goes down.

class PointyWizardHats{public:int mat[51][51],n,m;bool flag[51];int pre[51];bool dfs(int i){      for(int j=0;j<m;j++)      if(!flag[j]&&mat[i][j]){  flag[j]=true;          if(pre[j]==-1||dfs(pre[j])){  pre[j]=i;           return true;           }                }               return false; }      int getNumHats(vector <int> topHeight, vector <int> topRadius, vector <int> bottomHeight, vector <int> bottomRadius){n=topHeight.size();m=bottomHeight.size();memset(mat,0,sizeof(mat));for(int i=0;i<n;i++)for(int j=0;j<m;j++)if(topRadius[i]<bottomRadius[j]&&(double)topHeight[i]/topRadius[i]>(double)bottomHeight[j]/bottomRadius[j])mat[i][j]=1;int ans=0;memset(pre,-1,sizeof(pre));for(int i=0;i<n;i++){memset(flag,false,sizeof(flag));if(dfs(i))ans++;}    return ans;}};

1000pt: I had no idea when I read the question.

Is a status compressed DP.

Class orderofthehats {public: int minchanged (vector <string> spellchart) {int n = spellchart. size (); DP [0] = sum [0] = 0; For (INT I = 1; I <(1 <n); I ++) {sum [I] = sum [I> 1] + (I & 1); DP [I] = inf;} int A [20]; // A [I] indicates the memset (A, 0, sizeof (a); For (INT I = 0; I <N; I ++) for (Int J = 0; j <n; j ++) if (spellchart [I] [J] = 'y ') A [I] | = (1 <j); For (INT I = 0; I <(1 <n); I ++) for (Int J = 0; j <n; j ++) if (I & (1 <j) = 0) DP [I | (1 <j)] = min (DP [I | (1 <j)], DP [I] + sum [A [J]-sum [I & A [J]); // indicates that J points are traversed Based on I, and all J restrictions but not in I are deleted. Return DP [(1 <n)-1] ;}};

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.