首页 > ACM题库 > HDU-杭电 > hdu 3752 Is the one been second-killed first?[解题报告]C++
2015
02-22

hdu 3752 Is the one been second-killed first?[解题报告]C++

Is the one been second-killed first?

问题描述 :

Long long ago, a problem was spread all over the world , but no one could solve it . Now, due to the Internet , it has been solved perfectly(See figure 1).
HDU CakeMan

Now here’s a problem much harmonious.
ErEr has big cake weighing m grams , at the same time he has n children . and every children want a part of the cake weighs even number(偶数) of grams. The children are extremely hungry and want to start their meal as soon as possible, that’s why you should help them and find out, if they can divide the cake in the way they want. For sure, each of them should get a part of positive weight.

输入:

The first line of input gives the number of cases, T (at most 100).
each case has there numbers m,n. (1<=m<=10000,1<=n<=100)

输出:

The first line of input gives the number of cases, T (at most 100).
each case has there numbers m,n. (1<=m<=10000,1<=n<=100)

样例输入:

2
10 2
11 2

样例输出:

YES
NO

#include <stdio.h>
int main(){
    int t,m,n;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&m,&n);
        printf("%s\n",(m%n==1||m/2<n)?"NO":"YES");
    }
}

 


  1. a是根先忽略掉,递归子树。剩下前缀bejkcfghid和后缀jkebfghicd,分拆的原则的是每个子树前缀和后缀的节点个数是一样的,根节点出现在前缀的第一个,后缀的最后一个。根节点b出现后缀的第四个位置,则第一部分为四个节点,前缀bejk,后缀jkeb,剩下的c出现在后缀的倒数第2个,就划分为cfghi和 fghic,第3部分就为c、c

  2. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。

  3. #include <cstdio>
    #include <cstring>

    const int MAXSIZE=256;
    //char store[MAXSIZE];
    char str1[MAXSIZE];
    /*
    void init(char *store) {
    int i;
    store['A']=’V', store['B']=’W',store['C']=’X',store['D']=’Y',store['E']=’Z';
    for(i=’F';i<=’Z';++i) store =i-5;
    }
    */
    int main() {
    //freopen("input.txt","r",stdin);
    //init(store);
    char *p;
    while(fgets(str1,MAXSIZE,stdin) && strcmp(str1,"STARTn")==0) {
    if(p=fgets(str1,MAXSIZE,stdin)) {
    for(;*p;++p) {
    //*p=store[*p]
    if(*p<’A’ || *p>’Z') continue;
    if(*p>’E') *p=*p-5;
    else *p=*p+21;
    }
    printf("%s",str1);
    }
    fgets(str1,MAXSIZE,stdin);
    }
    return 0;
    }