"Uoj Goodbye Jiawu"

Source: Internet
Author: User
Tags rounds cmath

A. New Year's chocolate bar

This question my practice is: if have 2^k a chocolate so very good calculate, so the given number binary split;

2 Get 1, 4 get 3,8 get 7 ... Each one is twice times the previous one +1

#include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring >using namespace Std;int main () {int T;        scanf ("%d", &t), while (t--) {int n;scanf ("%d", &n), if (n<=1) puts ("0"); Else{int ans=0,now=1;n>>=1; while (n) {if (n&1) ans+=now;now=now*2+1;n>>=1;} printf ("%d\n", ans);}} return 0;}


B. Cancer of the New Year

It is easy to get "cancer" of the degree must be M (n-2), and the deletion of "cancer" can also constitute a tree, then the cancer must not be cut point.


So the necessary and sufficient condition of cancer is: degree =m-(n-2); not cut.


For the m=n-2 map to special treatment, there must be a point in this diagram is isolated, and this point must be a cancer


#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < Algorithm> #define M 100005using namespace Std;int is[m],tot,v[m],du[m],h[m],low[m],iscut[m],pre[m],dfs_clock=0; int n,m;struct edge{int x, y;} E[m*2];struct edge{int Y,ne;} E[m*3];bool ok=false;int cnt=0;void addedge (int x,int y) {e[++tot].y=y;e[tot].ne=h[x];h[x]=tot;} void Tarjan (int u,int fa) {low[u]=pre[u]=++dfs_clock;int child=0;for (int i=h[u];i;i=e[i].ne) {int v=e[i].y;if (!PRE[V]) {Child++;tarjan (v,u); Low[u]=min (Low[u],low[v]); if (Low[v]>=pre[u]) iscut[u]=1;} else if (PRE[V]&LT;PRE[U]&AMP;&AMP;V!=FA) low[u]=min (Low[u],pre[v]);} if (fa==0&&child==1) iscut[u]=0;} int main () {scanf ("%d%d", &n,&m), for (int i=1;i<=m;i++) {int x,y;scanf ("%d%d", &x,&y); Addedge (x, y), Addedge (y,x); e[i].x=x,e[i].y=y;du[x]++,du[y]++;} if (m==n-1) {int cnt=0;for (int i=1;i<=n;i++) if (du[i]==1) cnt++,is[i]=1;cout<<cnt<<endl;for (int i=1;i <=n;i++) if (Is[i]) cout<<i<< ""; Cout<<endl;return 0;} if (m==n-2) {for (int i=1;i<=m;i++) is[e[i].x]=1,is[e[i].y]=1;cout<<1<<endl;for (int i=1;i<=n;i++) if (!is[i]) Cout<<i<<endl;return 0;}        Tarjan (1,0); for (int i=1;i<=n;i++) if (!iscut[i]&&m-du[i]==n-2) cnt++,is[i]=1; cout<<cnt<<endl;for (int i=1;i<=n;i++) if (Is[i]) cout<<i<< ""; Cout<<endl;return 0;}

C. Board games for the New Year

Category discussion:

1. For the red Wolf, how many must be directly out of the


2. For the United States and sheep, the first judge whether to win through her, if you can, directly out of; if not, she is not useless, can be as the other side out of the wolf "threat", so that the other side has been kept in the hands of the gray wolf more than their own (let the other side dare not out too much wolf)


3. The next step is to consider the Grey Wolf and the pleasant goat: Calculate the minimum number of innings needed to win the two sides, whichever is the winner (take into account the threat of US sheep and goats)

#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include < cstdlib> #include <cmath> #define INF 0x3f3f3f3fusing namespace Std;int a[5],b[5];void D () {puts ("Draw");} void X () {puts ("Xiyangyang");} void M () {puts ("Meiyangyang");}        int main () {int T; scanf ("%d", &t), while (t--) {for (int i=1;i<=4;i++) cin>>a[i];for (int i=1;i<=4;i++) cin>>b[i];b[  1]-=a[3],a[3]=0; The red Wolf of the Initiator if (b[1]<0) {M (); continue;} if (a[4]&&a[1]>=b[1])//initiator of the United States Sheep {M (); continue;} if (A[1]&&!b[2]) {M (); continue;}  a[1]-=b[3],b[3]=0; The Red Wolf if (a[1]<0) {X (); continue;} if (b[4]&&b[1]>=a[1])//The United States sheep of the continue {X ();                int x=inf,y=inf; if ((!b[4]&&a[1]>b[2)) | | (B[4]&&a[1]>b[1]+b[2])) X=b[2]+1;if ((!a[4]&&b[1]>a[2]) | | (A[4]&&b[1]>a[1]+a[2])) Y=a[2]+1;if (X==inf&&y==inf) d (); else if (x<=y) {if (b[1]>=x-1&&x-1>a[2]) d (); else M ();} Else{if (a[1]<=b[1]+1&AMP;&AMP;A[1]&GT;=Y-1&AMP;&AMP;Y-1&GT;B[2]) d (); else if (a[1]>b[1]+1&&a[1]>=y&&y>b[2]) d (); Else X ();}} return 0;}


D. New Year's Qaq

I made a point of 70 points, first Judge N is a few, and then output the answer. The method for judging n is a number from 0 to 16 to see which is the same as N. To avoid judging the same error, my approach is:

If the judgment is equal, then the judgment is equal again, if it is equal, then the judgment is equal; if not equal, judge from the beginning.

If the judgments are not equal, then the judgment is not equal again, if not equal, then the judgment is unequal; if equal, judge from the beginning.


After a few rounds (I have 4 rounds), if each judgment is the same, then this judgment is basically guaranteed to be correct.


The following is a program builder.


#include <iostream> #include <cstdio> #include <iostream>using namespace Std;int f[100];int main () { Freopen ("T.out", "w", stdout), f[0]=0,f[1]=1;for (int i=0;i<=16;i++) {printf ("a =%d", i);cout<< "\\n";p rintf (" b = A = = n ");cout<<" \\n ";p rintf (" If B goto%d ", 72+i*3);cout<<" \\n "; Go is printf ("If e goto%d\\n", 123+i*3);  Go no}//1 for (int i=0;i<=16;i++) {printf ("b = a = = n\\n");p rintf ("If B goto%d\\n", 174+i*3);  Go is printf ("If e goto%d\\n", 4+4*i);  Return to judge the current number}for (int i=0;i<=16;i++) {printf ("b = a = = n\\n");p rintf ("If B goto%d\\n", 4+4*i);  Return to judge the current number of printf ("If e goto%d\\n", 225+i*3);  Go to No}//2 for (int i=0;i<=16;i++) {printf ("b = a = = n\\n");p rintf ("If B goto%d\\n", 276+i*3);  Go is printf ("If e goto%d\\n", 4+4*i);  Return to judge the current number}for (int i=0;i<=16;i++) {printf ("b = a = = n\\n");p rintf ("If B goto%d\\n", 4+4*i);  Return to judge the current number of printf ("If e goto%d\\n", 327+i*3); Go to No}//3 for (int i=0;i<=16;i++) {printf ("b = a = = n\\n");p rintf ("IF B goto%d\\n ", 378+i*3);  Go is printf ("If e goto%d\\n", 4+4*i);  Return to judge the current number}for (int i=0;i<=16;i++) {printf ("b = a = = n\\n");p rintf ("If B goto%d\\n", 4+4*i);  Return to judge the current number of printf ("If e goto%d\\n", 429+i*3);  Go to No}//4for (int i=0;i<=16;i++) {printf ("b = a = = n\\n");p rintf ("If B goto%d\\n", 480+i*3);  Output printf ("If e goto%d\\n", 4+4*i);  Return to judge the current number}for (int i=0;i<=16;i++) {printf ("b = a = = n\\n");p rintf ("If B goto%d\\n", 4+4*i);  Return to judge the current number of printf ("If e goto%d\\n", 4+4* (i+1)); Return to continue judging the next number} for (int i=0;i<=16;i++) {if (i>1) f[i]=f[i-1]+f[i-2];p rintf ("a =%d", f[i]);cout<< "\\n";p R intf ("Output a");cout<< "\\n";cout<< "If e goto 100000\\n";} return 0;}


Sentiment:

The exam can not be more rotten, the second question unexpectedly begged the side double. The third topic category discusses writing hangs.

Still too weak, seriously brush the question bar ...


If you want to output "\ n", add a "\" first to output.


"Uoj Goodbye Jiawu"

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.