24h購物| | PChome| 登入
2013-09-15 22:19:30| 人氣1,768| 回應2 | 上一篇 | 下一篇

[UVA][STL] 12318 - Digital Roulette

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


  Digital Roulette 

John is developing a videogame that allows players to bet in a wall roulette. Players may bet for integer numbers from 0 to N, for some N$ ge$ 0 that represents the maximum number in the roulette.


Of course, the roulette behaves digitally. As a matter of fact, John designed its way to choose a value in the interval 0..N (the result of spinning the roulette) with a digital trigger that moves the roulette with a force that depends on an integer value x randomly chosen in the interval 0..M, where M$ ge$ 0 (M is the maximal appliable force). The roulette turns around a distance equivalent to P(x), where P is a polynomial with integer coefficients. One distance unit represents a displacement of one roulette number, counting clockwise.


It is clear that some result values may be produced by different chosen force values. Also, depending on the mechanism parameters, some numbers in the roulette may be not attainable regardless of the force value. For example, if N = 7, M = 5 and P(x) = x2 + 1, the mechanism can generate only three different results:

epsfbox{p12318.eps}


John wants to know how many different result values may be attained by his mechanism. Can you help him?

Input 

There are several cases to analyze. Each case is described by three lines:

  • The first line contains two non-negative integer numbers N and M, separated by a blank ( 1 $ leq$ N $ leq$ 107, 0 $ leq$ M $ leq$ 105).
  • The second line contains an integer k, the grad of the polynomial P ( 0 $ leq$ k $ leq$ 10).
  • The third line contains k + 1 integers a0, a1,..., ak separated by blanks, indicating the integer coefficients that define the polynomial P, i.e., P(x) = akxk + ... + a1x + a0. You can assume that 0 $ leq$ ai $ leq$ N for each 0 $ leq$ i $ leq$ k. If k > 0 then you may assume that ak $ neq$ 0.

The last test case is followed by a line containing two zeros.

Output 

For each case, print one line indicating how many different numbers are attainable by John's mechanism.

Sample Input 

7 5
2
1 0 1
99 10
0
5
99 10
1
5 25
99 10
1
3 29
99 10
2
3 29 31
0 0

Sample Output 

3
1
4
11
10



題目描述:

現在有兩個轉盤,根據一套公式使其套用到另一個轉盤,問最多有多少種可能。

題目解法:

窮舉所有可能帶入函數,並且去重複。



#include <stdio.h>
#include <set>
using namespace std;
int ai[15];
int main() {
    int n, m, k;
    int i, j;
    while(scanf("%d %d", &n, &m) == 2 && n+m) {
        scanf("%d", &k);
        for(i = 0; i <= k; i++)
            scanf("%d", &ai[i]);
        set<int> S;
        for(i = 0; i <= m; i++) {
            long long val = 0, x = 1;
            for(j = 0; j <= k; j++) {
                val += ai[j]*x, val %= n+1;
                x = (x*i)%(n+1);
            }
            S.insert(val);
        }
        printf("%d\n", S.size());
    }
    return 0;
}

台長: Morris
人氣(1,768) | 回應(2)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA] 11474 - Dying Tree
此分類上一篇:[UVA][樹形背包] 1222 - Bribing FIPA

sexe videos
love Thank...
2018-06-09 23:45:03
sesso videos
love Thank...
2018-06-09 23:46:14
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文