计蒜课/百度的年会游戏(枚举)

题目链接:https://nanti.jisuanke.com/t/15503

 

题意:中文题诶~

 

思路:一开始想写的直接模拟gg了,赛后才想到这里可以直接枚举两个色子的点数,再来判断一下当前情况是否可行就好了...

 

代码:

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int a[5], x, y;
 5 
 6 void yxl(int& fx, int& cnt){
 7     while(a[cnt] < fx){
 8         fx -= a[cnt];
 9         cnt--;
10         if(!cnt) cnt = 4;
11     }
12 }
13 
14 bool is_ok(int fx, int fy){
15     int cnt = fx+fy;
16     cnt %= 4;
17     if(!cnt) cnt = 4;
18     fx += 1;
19     yxl(fx, cnt);
20     if(cnt==x && y==fx) return true;
21     fx += 8;
22     yxl(fx, cnt);
23     if(cnt==x && y==fx) return true;
24     fx += 8;
25     yxl(fx, cnt);
26     if(cnt==x && y==fx) return true;
27     return false;
28 }
29 
30 int main(void){
31     int ans=0;
32     cin >> a[1] >> a[2] >> a[3] >> a[4] >> x >> y;
33     for(int i=1; i<=6; i++){
34         for(int j=i; j<=6; j++){
35             if(is_ok(i, j)) ans++;
36         }
37     }
38     cout << ans << endl;
39     return 0;
40 }
View Code

 

posted @ 2017-05-22 10:54  geloutingyu  阅读(196)  评论(0编辑  收藏  举报