"Forward" ◇ 3rd station ◇codeforces Round #512 DIV2

Source: Internet
Author: User

"3rd Station" Codeforces Round #512 Div2

The third question inexplicable card half-day ... A bunch of details have not been dealt with, and another one is found. And then it blew up, and it took a phala of time.

The rating fell again ... But nothing, much better than the last time:)

+ Portal +

◇ Brief summary

The first two questions are very OK, the second drop is OK. The mentality explosion starts from the third question ... At the beginning of the design of the judgment method did not consider 0, and then the wrong many times, and then changed after the whole number to be divided into 2 and more, continue WA, finally the entire program deleted the re-magic changed a finally AC. It feels like the final AC code is a bit more complex than the original, but after all AC, it's nice (it doesn't seem like the lower the complexity, the better).

And then basically the course is this:

Look at the first two--happy cut off----look at three questions--and it seems very simple: Gt Back to the end of the game, AC-C

◇ Topic & Resolution A. In Search of a easy problem

· Translation

The author is trying to make the first question easier. So he investigated n individuals, if I personally think the problem is more difficult, the person will get feedback "1", otherwise get feedback "0". The problem is thought to be simple when the subject gets all the feedback "0".

Enter N to indicate the number of respondents. gives the number of n 0 or 1 for each person's feedback.

If the problem is considered simple, output "easy", otherwise output "hard".

· Resolution

Enter in turn, with a bool variable to determine if there is a "1", if there is output "hard", otherwise the output "easy".

· [Source code]

/*lucky_glass*/#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int N; int main () {scanf ("%d", &n), bool x=false;for (int i=0,num; i<n; i++) {scanf ("%d", &num); x|=num;} printf ("%s\n",!x?) Easy ': Hard '); return 0;}
B. Vasya and Cornfield

· Translation

There is a rectangular field in the middle of a square with a side length of N, and the coordinates of the four corners of the field are (0,d), (d,0), (n,n−d) (n−d,n).< Span id= "mjxc-node-19" > < Span id= "Mathjax-element-4-frame" data-mathml= " ( n & #x2212; D , N ) "> < Span id= "mjxc-node-36" >

There are m locusts in some coordinates of this land, and the farmer wants to know which locusts are in the field.

Give the n,d,m, and the coordinates of each locust (all integers, and each edge of the rectangle greater than 0), to determine whether each locust is in the field.

· Resolution

Full of "if" ...

Probably at first I took care of one--if D is greater than N/2, I can flip the original image around, and put n-d as the new D value ... This is the following:

Force the situation to change ... To do this, I assign the BOOL variable flag to true to indicate that it needs to be flipped.

After entering the coordinates of the insect if flag is true, the X is changed to N-x, that is, a flip

Next, according to the insect's ordinate classification discussion--

①0≤y≤d: In the field is the D-y≤x≤d+y

②d<y<n-d: In the field is the Y-d≤x≤y+d

③n-d≤y≤n: In the field is the Y-d≤x≤2n-d-y

Output can be.

· [Source code]

/*lucky_glass*/#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int n,d, Q;int Main () {scanf ("%d%d%d", &n,&d,&q), bool flag= (n<d*2), if (flag) D=n-d;while (q--) {int x,y;scanf ("%d %d ", &x,&y), if (flag) y=n-y;if (Y<=d) {if (d-y<=x && x<=d+y) printf (" yes\n "); elseprintf (" no\n "); );} else if (d<y && y<n-d) {if (y-d<=x && x<=y+d) printf ("yes\n"); elseprintf ("no\n");} else {if ( N-d-(n-y) <=x && x<=n-d+ (n-y)) printf ("yes\n"); elseprintf ("no\n");}} return 0;}
C. Vasya and Golden Ticket

· Translation

Vasya has a string of numbers that he wants to divide into multiple (≥2) non-overlapping substrings, and each element belongs to at least one substring, satisfying the sum of the numbers in each substring.

Whether the output is possible.

· Resolution

You can first store a string of numbers in strings.

Enumerates the first substring with a range of 1~i digits. Assuming this is possible, you can first calculate the GAL and the number in each substring. Use Tot to count the sum of the current substring numbers, enumerate each number in turn, and add to the current substring-if tot>gal, the description cannot be completed, if Tot==gal and the next one is not 0 (if 0 can continue to add to the current substring), the substring has reached the target , tot zeroing, records the next substring, the number of substrings separated by CNT records. If you enumerate to the last number, determine if tot is equal to the GAL. A special sentence-if gal==0, determine whether the whole string is 0.

Finally, you can save the answer with BOOL and determine if CNT is ≥2 and then output.

· [Source code]

/*lucky_glass*/#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int N; Char Strnum[105];int main () {scanf ("%d%s", &n,strnum), int gal=0;for (int i=0; i<n-1; i++) {gal+=strnum[i]-' 0 '; int Tot=0,cnt=0;bool ok=true;for (int j=0; j<n; J + +) {if (gal==0) {if (strnum[j]!= ' 0 ') {ok=false;break;} elsecnt++;} else{tot+=strnum[j]-' 0 '; if (tot>gal) {ok=false;break;} if (j==n-1 && tot!=gal) {ok=false;break;} if (tot==gal && strnum[j+1]!= ' 0 ') tot=0,cnt++;}} if (ok && cnt>=2) {printf ("yes\n"); return 0;}} printf ("no\n"); return 0;}

The EndThanks for reading!

-Lucky_glass

(Tab: If I have not clear the place can be directly in the mailbox [email protected] email me, on the weekend I will try to answer and improve the blog ~?? )

"Forward" ◇ 3rd station ◇codeforces Round #512 DIV2

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.