UVA 11636 Hello world,la 3602 DNA Consensus string,uva 10970 Big chocolate,uva 10340 All in All,uva 11039 Building Designi Ng

Source: Internet
Author: User

The course is very tight, can only brush some water problem, almost are greedy.

UVA 11636 Hello World

The answer to the power of two is that the binary length minus 1, not the power of two is the binary length.

#include <cstdio>intMain () {intN,kas =0;  while(SCANF ("%d", &n),n>0){        intR =0;  for(n--;n;n>>=1) r++; printf ("Case %d:%d\n",++kas,r); }    return 0;}

LA 3602 DNA Consensus String

Greedy structure, each one of the most frequently-seen.

#include <bits/stdc++.h>using namespacestd;Const intMAXM = -, MAXN = 1e3+1;intid[ the];CharRid[] ="ACGT";intct[4][MAXN];Chars[maxn+5];intMain () {id['A'] =0; id['C'] =1; id['G'] =2; id['T'] =3; intT;cin>>u;  while(t--){        intM,n; scanf"%d%d",&m,&N);  for(inti =0; I <4; i++) Fill (ct[i],ct[i]+n,0);  for(inti =0; I < m; i++) {scanf ("%s", s);  for(intj =0; J < N; J + +) {Ct[id[s[j]]][j]++; }        }        intsum =0;  for(intj =0; J < N; J + +){            intK =0;  for(inti =1; I <4; i++)if(Ct[i][j] > ct[k][j]) k =i; Putchar (Rid[k]); Sum+ = mCt[k][j]; } printf ("\n%d\n", sum); }    return 0;}

UVA 10970 Big Chocolate (equivalent conversion)

The minimum number of knives is confusing, from the block count, each cut will only add one piece of chocolate.

#include <bits/stdc++.h>usingnamespace  std; int Main () {    int  m,n;      while (~SCANF ("%d%d",&m,&N)) {        printf ("%d\n  ", m*n-1);    }     return 0 ;}

Greedy selection, two pointers, T in the current element can choose to choose, do not select this element to the answer will not contribute, will not be better.

#include <bits/stdc++.h>using namespacestd;Const intMAXN =1e5;CharS[MAXN],T[MAXN];intMain () { while(~SCANF ("%s%s", S,t)) {        Char*p = S,*q =T;  while(*p) {             while(*q && *q! = *p) q++; if(!*Q) Break; P++; q++; }        if(!*p) puts ("Yes"); ElsePuts"No"); }    return 0;}

UVA 11039 Building Designing

Greedy, according to the absolute order, record the last symbol, you can choose to choose.

#include <bits/stdc++.h>using namespacestd;Const intMAXN = 5e5+5;intA[MAXN];BOOLcmpintAintb) {returnABS (a) <ABS (b);}intMain () {intT Cin>>T;  while(t--){        intN scanf"%d",&N);  for(inti =0; I < n; i++) scanf ("%d", A +i); Sort (A,a+n,cmp); intAns =1;BOOLFG = a[0]>0;  for(inti =1; I < n; i++){            BOOLTFG = a[i]>0; if((TFG&AMP;&AMP;!FG) | | (!tfg&&FG)) {FG= TFG; ans++; }} printf ("%d\n", ans); }    return 0;}

UVA 11636 Hello world,la 3602 DNA Consensus string,uva 10970 Big chocolate,uva 10340 All in All,uva 11039 Building Designi Ng

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.