1. 程式人生 > >計蒜課/百度的年會遊戲(枚舉)

計蒜課/百度的年會遊戲(枚舉)

分享 題目 opened lan href ans ace play int

題目鏈接: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

計蒜課/百度的年會遊戲(枚舉)