TOJ 3474.The Big Dance
2017-07-10 19:23
232 查看
题目链接:http://acm.tju.edu.cn/toj/showp3474.html
3474. The Big Dance
Time Limit: 2.0 Seconds Memory Limit: 65536K
Total Runs: 517 Accepted Runs: 343 Multiple test files
Bessie and the herd, N (1 ≤ N ≤ 2,200) conveniently numbered 1..N cows in all, have gone to a dance where plenty of bulls are available as dancing partners. This dance is known
as the "odd cow out" dance because of the way cows are chosen to dance with bulls.
The cows are lined up in numerical order and the 'middle' point is chosen. It either divides the line of cows exactly in half or it is chosen so that the first set of cows has just one more cow in it than
the second set. If exactly two cows are in the set, they are chosen to dance with bulls. If one cow is in the set, she is sent home with a consolation prize of a beautiful rose.
If the set has more than two cows in it, the process is repeated perhaps again and again until sets with just one or two cows emerge.
The two cow ID numbers are multiplied together and added to a global sum.
Given the number of cows at the dance, compute the global sum after all the eligible cows are chosen.
Consider a dance with 11 cows numbered 1..11. Here is the sequence of dividing them:
So the sum for this dance would be 188.
简单的递归题,水题上代码:
3474. The Big Dance
Time Limit: 2.0 Seconds Memory Limit: 65536K
Total Runs: 517 Accepted Runs: 343 Multiple test files
Bessie and the herd, N (1 ≤ N ≤ 2,200) conveniently numbered 1..N cows in all, have gone to a dance where plenty of bulls are available as dancing partners. This dance is known
as the "odd cow out" dance because of the way cows are chosen to dance with bulls.
The cows are lined up in numerical order and the 'middle' point is chosen. It either divides the line of cows exactly in half or it is chosen so that the first set of cows has just one more cow in it than
the second set. If exactly two cows are in the set, they are chosen to dance with bulls. If one cow is in the set, she is sent home with a consolation prize of a beautiful rose.
If the set has more than two cows in it, the process is repeated perhaps again and again until sets with just one or two cows emerge.
The two cow ID numbers are multiplied together and added to a global sum.
Given the number of cows at the dance, compute the global sum after all the eligible cows are chosen.
Consider a dance with 11 cows numbered 1..11. Here is the sequence of dividing them:
1 2 3 4 5 6 | 7 8 9 10 11 1 2 3 | 4 5 6 1 2 | 3 1 2 => 1*2=2 added to sum -> sum=2 3 => sent home with rose 4 5 | 6 4 5 => 4*5=20 added to sum -> sum=22 6 => sent home with rose 7 8 9 | 10 11 7 8 | 9 7 8 => 7*8=56 added to sum -> sum=78 9 => sent home with rose 10 11 => 10*11=110 added to sum -> sum=188
So the sum for this dance would be 188.
Input
* Line 1: A single integer: NOutput
* Line 1: A single integer that is the sum computed as prescribed.Sample Input
11
Sample Output
188
简单的递归题,水题上代码:
#include <stdio.h> int cow(int start, int end){ if(start == end) return 0; if(end == start + 1) return end * start; int middle = (start + end)/2; return cow(start, middle) + cow(middle+1, end); } int main(){ int n; while(~scanf("%d",&n)) printf("%d\n",cow(1, n)); return 0; }
相关文章推荐
- toj3474 The Big Dance
- UVALive 6893 The Big Painting hash
- Architecture – Get The Big Picture
- 凸包 Graham扫描法 TOJ 1255 Surround the Trees&&TOJ 3100 女生寝室的围墙
- Some Practical Oral English come from 《The Big Bang》
- The Big Green Bus Comes to Seattle
- what is the difference between little-endian and big-endian.
- The annoying problem about my BIG TOE
- The Big Bang Theory -Barenaked Ladies Music Video
- CSU1908-The Big Escape-并查集
- [转]The Big List of JavaScript, CSS, and HTML Development Tools, Libraries, Projects, and Books
- Solve the confusion of Big Omega, Big Theta and Big O
- TOJ Code the Tree AC 代码 以及题解
- The Big Proxy List: Paid proxy list service - Thousands of fresh proxies!
- The Big Bang Theory
- the big bang
- 【HDU】1133 - Buy the Ticket(BigDecimal & 组合数学 & 递推)
- The BIG Torrent Client AIO
- The Differences between Little-Endian and Big-Endian
- [follow the big guy 001] Nicholas C. Zakas The best career advice I’ve received