24h購物| | PChome| 登入
2013-02-26 11:51:45| 人氣1,086| 回應0 | 上一篇 | 下一篇

[UVA][math] 11480 - Jimmy's Balls

推薦 0 收藏 0 轉貼0 訂閱站台

 
Problem J
Jimmy's Balls
Time Limit : 1 second
 

 

Jimmy has a very large bag full of balls. Each ball has a single color. There are three colors; red, blue and green. There is atleast one ball of each type and the number of blue balls is more than that of red balls. And the number of green balls is more than that of blue balls.

0 < number of red balls <  number of blue balls < number of green balls.

Given the total number of balls, how many different colored combinations can there be.

For N = 10, there are 4 combinations as shown in the diagram.

     

 

 
  Input    
  There will be many cases. Each case is an integer N ( 6 <= N <= 1000010 ). N denotes the total number of balls in the bag. Input is terminated with a 0.  
     
  Output  
  For each case, output the case number, followed by the answer. Look at the sample for clarification.  
     
  Sample Input Sample Output    
 

6
10
0

Case 1: 1
Case 2: 4

 
 

Problem Setter: Sohel Hafiz
Next Generation Contest 5

     

不推公式!

窮舉一最少的那個球數,然後用數學算出剩下的分配方法數。

#include <stdio.h>

int main() {
    int n, cases = 0;
    while(scanf("%d", &n) == 1 && n) {
        int a, b, c;
        long long res = 0;
        for(a = n/3; a >= 1; a--) {
            b = a+1;
            c = b+1;
            if(a+b+c <= n) {
                c--;
                res += (n-a-b-c+1)/2;
            }
        }
        printf("Case %d: %lld\n", ++cases, res);
    }
    return 0;
}

台長: Morris
人氣(1,086) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][MST] 12507 - Kingdoms
此分類上一篇:[UVA][Trie] 760 - DNA Sequencing

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文