Team Competition #2 problem solving Summary (BNU 11th Beijing Normal University Program Design Competition ),

Source: Internet
Author: User

Team Competition #2 problem solving Summary (BNU 11th Beijing Normal University Program Design Competition ),

Competition link: click here ~~

A bnu acm team schedule, Simulation ~~ Hand speed question:

#include <iostream>#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>using namespace std;int main(){    int t;    scanf("%d", &t);    while (t--)    {        int tmp;        scanf("%d", &tmp);        switch (tmp)        {        case 1:            printf("Unknown\n");            break;        case 2:        case 3:            printf("Spring Training\n");            break;        case 4:            printf("Spring Training\nBNU Contest\n");            break;        case 5:        case 6:            printf("Unknown\n");            break;        case 7:            printf("Practice Week\nSummer Training\n");            break;        case 8:            printf("Summer Training\n");            break;        case 9:        case 10:            printf("Regional Contest\n");            break;        case 11:            printf("Basic Training\nRegional Contest\n");            break;        case 12:            printf("Basic Training\nRookie Contest\n");            break;        }    }    return 0;}

B desert tour

There should be multiple backpacks. I didn't think so much at the time. I used to simulate them.

# Include <iostream> # include <stdio. h> # include <math. h> # include <string. h ># include <algorithm> using namespace std; int I, j, L, X, N; bool flag; int a [1005]; int aa [2100]; int main () {int t; scanf ("% d", & t); while (t --) {scanf ("% d", & L, & X, & N); for (int I = 0; I <N; I ++) {scanf ("% d", & a [I]);} memset (aa, 0, sizeof (aa); int ANS; for (int I = 0; I <N; I ++) // n ^ 2 the complexity is processed by a combination of {for (int j = 0; j <N; j ++) {ANS = a [I] + a [j]; // 4 5 5 6 // cout <ANS <endl; aa [ANS] = 1 ;}} bool flag = 0; int t = L-X; // 11 for (int I = 1; I <t; I ++) {if (aa [I] & aa [t-I]) // jump out of {puts ("Yes"); flag = 1; break ;}} if (flag = 0) puts ("No ");} return 0 ;}

C. Adidas vs Adivon

[Solution ]:

Judge, continue to/2 in the Process of semi-cutting until it is an odd number or 0. The number of times is counted. The sum of the length and width. You can judge the parity.

#include <iostream>#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>using namespace std;int i,j,L,X,N;bool flag;int a[1005];int aa[2100];int main(){    int t,m,n;    cin>>t;    while(t--)    {        int sum=0;        scanf("%d%d",&m,&n);        while(m%2==0)        {            m=m/2;            sum++;        }        while(n%2==0)        {            n=n/2;            sum++;        }        if(sum%2!=0)            printf("Adidas loses\n");        else            printf("Adivon prevails\n");    }    return 0;}
F. Taiko taiko

[Solution Thinking] One case is Y. In one case, if N is Y, add 1 by recursion. If N is used, there is no score. a1 = (a1 + 1) * p; b1 + = a1; accumulate.

#include <iostream>#include <stdio.h>#include <math.h>#include <vector>#include <map>#include <set>#include <string.h>#include <algorithm>using namespace std;int i,j,L,X,N;bool flag;int a[1005];int aa[2100];int main(){    int t,n,m,i,j;    double a1,b1,p;    scanf("%d",&t);    while(t--)    {        a1=b1=0;        scanf("%d%lf",&n,&p);        for(i=1;i<=n;i++){            a1=(a1+1)*p;            b1+=a1;        }        printf("%.6lf\n",b1);    }    return 0;}
H. Coin Question II

Probability, not explained ..

#include <stdio.h>#include <string.h>int main(){    int t;    scanf("%d",&t);    while (t--)    {        double n;        scanf("%lf", &n);        printf("%.2lf\n", 1/(n * (1 - n)));    }    return 0;}

J. chatla of Naruto

[Solution Thinking]: An interesting question is an IQ test!

My idea: launch a task at most twice, enter a number, and update the maximum value of the previous update each time. For details, see the code.

# Include <iostream> # include <stdio. h> # include <math. h> # include <vector> # include <map> # include <set> # include <string. h ># include <algorithm> using namespace std; int Minn =-0x3f3f3f; int main () {int I, j, c, x, n, m; int a1, a2, a3, a4, a5; cin> c> n; a1 = c; a2 = a3 = a4 = a5 = Minn; for (I = 1; I <= n; I ++) {cin> x; if (a1> = x) a2 = max (a2, a1-x ); // 9-9-9-9-9-9/* Find the minimum consumption, that is, the maximum remaining */a3 = max (a3, a2 + x ); // 10-11-12-12-14/* Step 2 find the next launch (that is The first launch) can increase the most */if (a3> = x) a4 = max (a4, a3-x ); // 9-9-9-10-10/* in step 3, find the smallest consumption of the second launch, and the largest remaining a5 = max (a5, a4 + x ); // 10-11-12-12-15/* Find the largest one! */} Int res1 = max (a3, a5); // 11-12-12-15 int res2 = max (a1, res1 ); // 11-12-12-15 cout <res2 <endl; // 15 !} /* 1 10-9: Start, change to 92 9: Do not start, 93 12: End 1 time, add 3 to 122 12-10 to start, end at 105 15, and add 5 to 15! */

L

[Solution ]:

Calculate the size of the area with the smallest area of the line and the rectangle. There are six situations:

1: a straight line goes straight up and down to form two trapezoid shapes.

2: The straight line passes horizontally to the left and right to form two trapezoid shapes.

3: form a triangle and a Pentagon through the vertical and lower sides on the left to find the area of the triangle. The minimum must be the area of the triangle, or exactly two triangles are formed.

4: in the same way as 3, it goes through the vertical and lower lines on the right.

5: parallel to the top through the left, the same as 3.

6: parallel to the lower and left, the same as 5.

First, use the four sides of the rectangle and the linear equation to solve the intersection coordinate, and then use the known coordinate to find the trapezoid and Triangle Area (coordinate subtraction, pay attention to the order ), how can we determine which polygon is formed ?, Note that if the trapezoid is used, the upper and lower intersections must be within the given two coordinate ranges. If the triangle is used, there must be an intersection on the straight line of the rectangle. In this way, the result can be determined and finally compared, you can find the area.

# Include <stdio. h> # include <math. h> # include <string. h> # include <stdlib. h >#include <iostream >#include <algorithm> using namespace std; int main () {int n, x1, y1, xr, yr, a, B, c; cin> n; while (n --) {cin> x1> y1> xr> yr> a> B> c; double s, S; double xy0 = (c + B * y1) * 1.0/-a; // returns the upper and lower intersections. The lower intersection is double xy1 = (c + B * yr) * 1.0/-; // calculate the upper cross point double yx0 = (c + a * x1) * 1.0/-B; // intersection, obtain the left intersection double yx1 = (c + a * xr) * 1.0/-B; // left and right intersection, and find the right intersection bool t1 = (xy0> = x1) & (xy0 <= xr); // determine the bool t2 = (xy1> = x1) & (xy1 <= xr); // determine the border, in the top bool t3 = (yx0> = y1) & (yx0 <= yr); // you can determine the bool t4 = (yx1> = y1) on the left) & (yx1 <= yr); // determine the boundary, in the right side if (t1 & t2) // straight line in the upper and lower intersection s = (xy1 + xy0-2 * x1) * (yr-y1)/2.0; // trapezoid area, else if (t3 & t4) // straight line at left and right intersection s = (yx0 + yx1-2 * y1) * (xr-x1) /2.0; else if (t1 & t3) s = (yx0-y1) * (xy0-x1)/2.0; // Triangle Area, else if (t1 & t4) s = (yx1-y1) * (xr-xy0)/2.0; else if (t2 & t3) s = (yr-yx0) * (xy1-x1)/2.0; else if (t2 & t4) s = (xr-xy1) * (yr-yx1)/2.0; S = fabs (xr-x1) * (yr-y1); s = min (s, S-s); printf ("%. 3lf \ n ", s);} return 0 ;}



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.