JZOJ 4909. 【NOIP2017模拟12.3】李电下棋
生活随笔
收集整理的這篇文章主要介紹了
JZOJ 4909. 【NOIP2017模拟12.3】李电下棋
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Description
Input
Sample Input
4
2 1 2
3 1 2
4 2 4
6 2 4
Output
Sample Output
wfl
lidian
wfl
lidian
Data Constraint
Solution
觀察題目,k=i+j or k=|i?j|
所以——更相減損術(shù)!!!
又因為 gcd(a,b)=gcd(a,a?b)=gcd(a,a+b)
所以是 gcd(a,b) 的倍數(shù)的位置才能下得到。
那么計算即可!(注意開 longlong)
Code
#include<cstdio> using namespace std; typedef long long LL; int T; LL n,a,b; inline LL gcd(LL x,LL y){return (!y)?x:gcd(y,x%y);} int main() {scanf("%d",&T);while(T--){scanf("%lld%lld%lld",&n,&a,&b);LL ans=n/gcd(a,b);if(ans%2) printf("lidian\n"); else printf("wfl\n");}return 0; }總結(jié)
以上是生活随笔為你收集整理的JZOJ 4909. 【NOIP2017模拟12.3】李电下棋的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JZOJ 4822. 【NOIP2016
- 下一篇: JZOJ 4910. 【NOIP2017