1. 程式人生 > 實用技巧 >Namomo Cockfight Round 4 t-shirt game

Namomo Cockfight Round 4 t-shirt game

傳送門

t-shirt

根據題意寫程式碼即可, 在區間內的所有排名得到衣服的概率和 乘 發生在區間內的概率, 然後用 1 除一下就可以了

#define _rep(i,a,b) for(int i = (a); i <= (b); i++)
void task1() {
    int t; cin >> t;
    while(t--) {
        int l,r, z = 0; cin >> l >> r;
        double p1 = 1.0/(r-l+1), ans = 0.0;
        //cout << " p1 = " << p1 << "\n";
_rep(i,l,r) { ans += (1.0/(i)); } cout << fixed << setprecision(10) << 1.0/(ans*p1) << "\n"; } return; }
View Code

game

。。。一直wa,沒注意細節 當有兩個人都大於1金幣時, 肯定結束不了 我知道這個但是寫錯了。。。。

其實結論就是 第一個擁有金幣的人操作完以後就贏了, 比如說只有他一個人擁有金幣 namo 他肯定贏了 或者說還有一個人有且僅有一個金幣 namo他把這個金幣拿了 他也贏了, 其他情況都是遊戲結束不了的

#define _for(i,a,b) for(int i = (a); i < (b); i++)
void task2() {
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;    
        vector<int> a(n);
        int cnt1 = 0, cnt2 = 0, cnt3 = 0, f = 0;
        _for(i,0,n) {
            cin >> a[i];
            if(!f and a[i] >= 1
) f = i+1; if(a[i] >= 1) cnt1++; else cnt3++; } if(cnt1 == 1) {cout << f << "\n"; continue;} if(cnt1 == 2) { for(int i = n-1; i >= 0; i--) if(a[i] >= 1) { if(a[i] == 1) cout << f << "\n"; else cout << "namo\n"; break; } } else cout << "namo\n"; } return; }
View Code