標籤:names stat nts target most targe constrain main SQ
A - Happy Birthday!
Time limit : 2sec / Memory limit : 1000MB
Score: 100 points
Problem Statement
E869120‘s and square1001‘s 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces, respectively,
when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of pieces of cake?
Constraints
- A and B are integers between 1 and 16 (inclusive).
- A+B is at most 16.
[題目解釋]
有兩個人要吃一塊大蛋糕,兩人分別吃A,B塊,規定一個人不能吃相鄰的兩塊蛋糕.問他們能否吃到蛋糕?
[題目解析]
由抽屜原理可知當一個人吃8塊時每兩塊蛋糕中間隔1塊蛋糕,當一個人吃九塊時必定有一塊相鄰的兩塊蛋糕.於是我們只要保證A,B均滿足小於等於8即可.
[代碼]
/* Name: Happy Birthday! Author: FZSZ-LinHua Date: 2018 06 16 Exec time: 1ms Memory usage: 256KB Score: 100 Algorithm: Brute-force */# include "iostream"# include "cstdio"using namespace std;int a,b; int main(){ scanf("%d%d",&a,&b); if(a<=8 && b<=8){ printf("Yay!"); }else{ printf(":("); } return 0; }
[ABC 100] A-Happy Birthday!