1. 程式人生 > 實用技巧 >聯賽模擬測試15

聯賽模擬測試15

------------恢復內容開始------------

A.遊戲

(不)排序+亂搞/暴力/二分圖/冰茶几(正解) 均可AC
考場上手動模擬了20以內的資料都hack掉了
沒想到交上過了
,,,
就挺意外的

B.嘟嘟嚕

搞一搞,對於中間不用取模的地方,不再使用加法,而是直接乘過去,調整下標

Code
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;

inline int read(){
	int x = 0, w = 1;
	char ch = getchar();
	for(; ch > '9' || ch < '0'; ch = getchar()) if(ch == '-') w = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return x * w;
}

inline void write(register int x){
	if(x < 0) x = ~x + 1, putchar('-');
	if(x > 9) write(x / 10);
	putchar(x % 10 + '0');
}

signed main(){
    freopen("mayuri.in","r",stdin);
    freopen("mayuri.out","w",stdout);
    register int T = read();
    while(T--){
        int n = read(), m = read(), x = 0, i = m;
        for(register int j = 2; j <= min(n, m); j++)
            x=(x+m)%j;
        if(n <= m) printf("%d\n", x + 1);
        else{
            x += 1;
            while("GARY CSL"){
                int nxt = i + (int)ceil(1.0 * (i - x) / (m - 1));
                if(nxt > n)break;
                x = (x + (nxt - i) * m);
                if(x == nxt){
                    if(++nxt > n) break;
                    x = (x + m) % nxt;
                }else x %= nxt;
                i = nxt;
            }
            x += (n - i) * m;
            printf("%d\n", x);
        }
    }
    return 0;
}
**------------恢復內容結束------------**