AIM Tech Round (Div. 2)

Source: Internet
Author: User
Tags cmath

A. Save Luke

Test instructions: Give a person the length of D, and then give an interval length of 0~l, give you two bullets of speed v1,v2, two bullets from 0 and L to the middle of the shot (actually not bullets, is a kind of film in the type of the tooth machine and so on is a person trapped in the inside, The one on either side that has a sharp thorn in the middle, and asks the longest time Luke can survive.

Idea: Look at the code, easy to understand

1#include <cstdio>2#include <cmath>3 intMain ()4 {5     intD,l,v1,v2;6      while(SCANF ("%d%d%d%d", &d,&l,&v1,&v2)! =EOF)7     {8printf"%.6lf\n", (l-d) *1.0/(v1+v2));9     }Ten}

B. Making a String

Test instructions: A26-letter string that gives you the number of letters and the number of letters that can be placed on each letter, with certain rules when you make a string:

1. The number of each letter in the string cannot be more than the given quantity

2. The number of occurrences of each letter in the string is different

What is the longest string of questions?

Idea: Because of the different elements involved, so use set to do,

First put a WA in the 20th set of data code

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5#include <Set>6 using namespacestd;7 Long Longnum[ -],sum[ -];8 intMain ()9 {Ten     intN; One      while(SCANF ("%d", &n)! =EOF) A     {     -         Set<Long Long>p; -         Long Longtot=0; the          for(intI=0; i<n;++i) -scanf"%lld",&num[i]); -Sort (num,num+n); -          for(inti=n-1; i>=0;--i) { +              while(P.find (num[i])! =P.end ()) { -num[i]-=1; +             } A P.insert (Num[i]); attot+=Num[i]; -         } -printf"%lld\n", tot); -     } -}

This code, in the while Loop num[i] may be reduced to negative, so input 3 1 1 1 The answer would have been 0, but the output is 0

So we have to make a judgment on negative numbers.

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5#include <Set>6 using namespacestd;7 Long Longnum[ -],sum[ -];8 intMain ()9 {Ten     intN; One      while(SCANF ("%d", &n)! =EOF) A     {     -         Set<Long Long>p; -         Long Longtot=0; the          for(intI=0; i<n;++i) -scanf"%lld",&num[i]); -Sort (num,num+n); -          for(inti=n-1; i>=0;--i) { +              while((P.find (num[i])! =p.end ())) { -num[i]-=1; +             } A             if(num[i]<0) num[i]=0; at P.insert (Num[i]); -tot+=Num[i]; -         } -printf"%lld\n", tot); -     } -}

That's it.

Error code paste here is to remind yourself against a problem for their own code to do no loopholes can be found,

AIM Tech Round (Div. 2)

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.