1. 程式人生 > >JZOJ(中山紀中) 1984. 【普及組模擬賽】遊戲(atlantis.pas/cpp)

JZOJ(中山紀中) 1984. 【普及組模擬賽】遊戲(atlantis.pas/cpp)

題目:

http://blog.csdn.net/qq_35786326/article/details/79211470

題意:

求每一局遊戲的勝者是誰?而如果是MaoLaoDa勝,那麼還有輸出ta第一次至少要拿多少塊金塊

分析:

當看到題目的第一眼時,小編差點沒從坐位上掉下來,畢竟是10^1000002的範圍。但經過思考後,才發現這題有規律可循:當我們將輸入的金塊數,每個數位進行累加,得x。而如果x是3的倍數,那麼就是King will win而MaoLaoDa will win則反之,而ta至少要拿的塊數,則是x%3的結果 程式碼:
#include<cstdio>
#include<cstring>
#include<iostream> #include<cmath> #include<algorithm> #define LL long long using namespace std; inline LL read() { LL d=0,f=1;char s=getchar(); while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();} return d*f; } int main() { freopen("atlantis.in"
,"r",stdin); freopen("atlantis.out","w",stdout); int c; for(int i=1;i<=3;i++) { string s; cin>>s; c=0; for(int i=0;i<s.size();i++) c+=s[i]-48;//規律如上述,不多解釋 if(c%3==0) printf("King will win.\n"); else printf("MaoLaoDa will win.\n%d\n",c%3); } fclose(stdin); fclose(stdout); return
0; }