bzoj:1621: [Usaco2008 open]roads Around the Farm Fork Junction

Source: Internet
Author: User

Description John's N (1≤n≤1,000,000,000) cows are set off to explore the land around the ranch. They will walk along a road until they reach the fork (it can be thought that all intersections are like this). This time, the herd of cows may be divided into two groups, along the next two roads continue to walk.    If they go to the fork again, it is still possible to continue to split into two groups to continue walking. The way the cows split is odd: if the cows can be precisely divided into two parts, the two parts of the cattle are exactly the same as K (1≤k≤1000), then the fork herd will split.    Otherwise, the herd will not split, and they'll all stay here and eat grass peacefully. Please calculate how many cows will eventually eat grass in a calm manner. Input

two integers n and K.

Output

The last number of herds.

Sample INPUT6 2

INPUT DETAILS:

There is 6 cows and the difference in group sizes is 2.

Sample OUTPUT3

OUTPUT DETAILS:

There is 3 final groups (with 2, 1, and 3 cows in them).

6
/ \
2 4
/ \
1 3 Direct violence recursion on Ah, anyway 0MSPascal dafa good, instantly brush on the # # but the front 88KB is how to do it ...
#include <cstdio>using namespacestd;intn,m;intAintN) {    if(n>m&& (n-m)%2==0)returnA ((n-m)/2) +a ((n+m)/2);return 1;}intMain () {scanf ("%d%d",&n,&m); printf ("%d\n", A (n));}
var n,m:longint;function F (n:longint): Longintbegin if 2=022); exit (1); End;beginread (n,m); write (f (n)); end.

bzoj:1621: [Usaco2008 open]roads Around the Farm Fork Junction

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.