HDU Zhejiang Institute of Science and Technology School competition 2016

Source: Internet
Author: User

Let's go to play

Test instructions: give you n lines of information, F or M is to indicate that a woman or a man is available within the date of a-B. As a host you have to make sure that the day has been the largest number of people invited, and that this day comes as much as men and women.

Method: A total of 366 days a year, the information of each day to remember, and finally traverse, see which day can be invited to the largest number.

A very practical point ah. The company may be able to get it later. Write a program to run, the algorithm is simply hanging fried days.

#include <stdio.h>#include<algorithm>#include<string.h>#include<queue>using namespacestd;structnode{intA1; intB1; intC1;} viss[370];intMain () {intn,a,b; Charst[5];  while(~SCANF ("%d",&N) {memset (Viss,0,sizeof(Viss));  for(intI=0; i<n; i++) {scanf ("%s", ST); scanf ("%d%d",&a,&b); if(STRCMP (St,"F")==0)            {                 for(intJ=a; j<=b; J + +) {viss[j].a1++; if(VISS[J].A1==VISS[J].B1)//only boys and girls are likely to have the same number of times when it is necessary to save larger values. {viss[j].c1=viss[j].a1; }                }            }            Else if(STRCMP (St,"M")==0)            {                 for(intJ=a; j<=b; J + +) {viss[j].b1++; if(viss[j].a1==viss[j].b1) {VISS[J].C1=viss[j].b1; }                }            }        }        intmax1=-1;  for(intI=1; i<=366; i++)        {            if(viss[i].c1>max1) {Max1=Viss[i].c1; }} printf ("%d\n", max1*2);//because the number of boys or girls is saved, the total number should be two.     }    return 0;}

Tian Bogey horse racing

Test instructions: Give the speed of Tian bogey and Zi Wangma, and seek the optimal strategy.

Method: This greed is absolutely absolute.

There are three options for every field bogey: win, lose, or draw.

You can win without losing, a draw.

You can draw without losing.

If King out the best horse, Tian bogey to consider his fastest horse is not able to overcome the king fastest horse.

If defeated, then prevail. It is in line with the greedy strategy that can win without losing.

If it is defeated, it means that no matter which horse will be defeated in the field, it will be the worst one.

If a draw, the situation is somewhat complicated:

The draw indicates that it is not possible to win, just choose between a draw and a loss.

If there's a draw, there's no bonus to take,

See if the worst horse can beat King,

If the worst horse can beat King's worst horse, fight.

Until King the worst horse, indicating the worst horse who can not beat, doomed to lose, it is better to first give that draw sacrifice.

This greedy way of thinking is almost 666.

#include <stdio.h>#include<algorithm>#include<string.h>using namespacestd;inta[1011],b[1011];intMain () {intN;  while(~SCANF ("%d",&N)) { for(intI=0; i<n; i++) {scanf ("%d",&A[i]); }         for(intI=0; i<n; i++) {scanf ("%d",&B[i]); } sort (A,a+N); Sort (b,b+N); intmax1=n-1, max2=n-1; intmin1=0, min2=0; intsum=0;  for(intI=0; i<n; i++)        {            if(a[max1]<B[MAX2]) {Min1++; Max2--; Sum-= -; }            Else if(a[max1]>B[MAX2]) {Max1--; Max2--; Sum+= -; }            Else            {                if(a[min1]>B[min2]) {Sum+= -; Min1++; Min2++; }                Else                {                    if(a[min1]<B[MAX2]) {Sum-= -; } min1++; Max2--; }}} printf ("%d\n", sum); }    return 0;}

HDU Zhejiang Institute of Science and Technology School competition 2016

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.