zoukankan      html  css  js  c++  java
  • Codeforces题目 java程序员

    A - Watermelon
    Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

    Description

    One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showedw kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.

    Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired 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 watermelon in the way they want. For sure, each of them should get a part of positive weight.

    Input

    The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.

    Output

    Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; andNO in the opposite case.

    Sample Input

    Input
    8
    
    Output
    YES
    

    Sample Output

    Hint

    For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).

    MYCode:
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            if(n>2 && n%2==0)
            printf("YES\n");
            else
            printf("NO\n");
        }
    }
    //

    B - Before an Exam
    Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

    Description

    Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less thanminTimei and not more thanmaxTimei hours per eachi-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.

    So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hourssumTime spent him on preparation, and now he wants to know if he can show his parents a timetablesсhedule with d numbers, where each numbersсhedulei stands for the time in hours spent by Peter eachi-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of allschedulei should equal tosumTime.

    Input

    The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines contains two integer numbersminTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8), separated by a space — minimum and maximum amount of hours that Peter could spent in thei-th day.

    Output

    In the first line print YES, and in the second line printd numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or printNO in the unique line. If there are many solutions, print any of them.

    Sample Input

    Input
    1 48
    5 7
    
    Output
    NO
    
    Input
    2 5
    0 1
    3 5
    
    Output
    YES
    1 4 

    MYCode:

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    #define MAX 35
    int lt[MAX];
    int rt[MAX];
    int ans[MAX];
    int main()
    {
        int n,sum;
        while(scanf("%d%d",&n,&sum)!=EOF)
        {
            int s=0;
            int tot=0;
            int i;
            for(i=1;i<=n;i++)
            {
                scanf("%d%d",&lt[i],&rt[i]);
                s+=lt[i];
                ans[i]=lt[i];
                tot+=rt[i];
            }
            if(s>sum||tot<sum)
            {
                printf("NO\n");
                continue;
            }
            if(s<sum)
            {
                int add=sum-s;
                for(i=1;i<=n;i++)
                {
                    int tp=rt[i]-lt[i];
                    if(add-tp>0)
                    {
                        ans[i]+=tp;
                        add-=tp;
                    }
                    else
                    {
                        ans[i]+=add;
                        break;
                    }
                }
            }
            printf("YES\n");
            for(i=1;i<=n;i++)
            {
                printf("%d",ans[i]);
                if(i!=n)
                printf(" ");
            }
            printf("\n");
        }
    }
    //

    C - Registration system
    Crawling in process...Crawling failedTime Limit:5000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

    Description

    A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.

    Each time a new user wants to register, he sends to the system a request with hisname. If such aname does not exist in the system database, it is inserted into the database, and the user gets the responseOK, confirming the successful registration. If thename already exists in the system database, the system makes up a new user name, sends it to the user as a prompt andalso inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another toname (name1,name2, ...), among these numbers the leasti is found so that namei does not yet exist in the database.

    Input

    The first line contains number n (1 ≤ n ≤ 105). The followingn lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.

    Output

    Print n lines, which are system responses to the requests:OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.

    Sample Input

    Input
    4
    abacaba
    acaba
    abacaba
    acab
    
    Output
    OK
    OK
    abacaba1
    OK
    
    Input
    6
    first
    first
    second
    second
    third
    third
    
    Output
    OK
    first1
    OK
    second1
    OK
    third1
    

    MYCode:
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<string>
    #include<map>
    using namespace std;
    map<string,int> list;
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            list.clear();
            int i;
            string str;
            for(i=1;i<=n;i++)
            {
                cin>>str;
                if(list.find(str)!=list.end())
                {
                    list[str]++;
                    cout<<str<<list[str]<<endl;
                }
                else
                {
                    list[str]=0;
                    cout<<"OK"<<endl;
                }
            }
        }
    }
    //

    D - Mysterious Present
    Crawling in process...Crawling failedTime Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

    Description

    Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make achain. Chain here is such a sequence of envelopesA = {a1,  a2,  ...,  an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the(i  -  1)-th envelope respectively. Chain size is the number of envelopes in the chain.

    Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes.

    Peter has very many envelopes and very little time, this hard task is entrusted to you.

    Input

    The first line contains integers n, w, h (1  ≤ n ≤ 5000,1 ≤ w,  h  ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follown lines, each of them contains two integer numberswi andhi — width and height of thei-th envelope (1 ≤ wi,  hi ≤ 106).

    Output

    In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers.

    If the card does not fit into any of the envelopes, print number 0 in the single line.

    Sample Input

    Input
    2 1 1
    2 2
    2 2
    
    Output
    1
    1 
    
    Input
    3 3 3
    5 4
    12 11
    9 8
    
    Output
    3
    1 3 2 
    

    //

    MYCode:

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    #define MAX 5010
    int pre[MAX];
    struct node
    {
        int w;
        int h;
        int id;
    }a[MAX];
    int dp[MAX];
    int  st[MAX];
    bool cmp(node a,node b)
    {
        if(a.w!=b.w)
        return a.w<b.w;
        else
        return a.h<b.h;
    }
    int main()
    {
        int n,ww,hh;
        while(scanf("%d",&n)!=EOF)
        {
            scanf("%d%d",&ww,&hh);
            int i,j;
            for(i=1;i<=n;i++)
            {
                scanf("%d%d",&a[i].w,&a[i].h);
                a[i].id=i;
            }
            sort(a+1,a+n+1,cmp);
            memset(pre,0,sizeof(pre));
            memset(dp,0,sizeof(dp));
            int ans=0;
            int index=0;
            for(i=1;i<=n;i++)
            {
                int res=0;
                if(a[i].w>ww && a[i].h>hh)
                {
                    for(j=i-1;j>=1;j--)
                    {
                        if(a[j].w<a[i].w&&a[j].h<a[i].h)
                        {
                            if(dp[j]>res)
                            {
                                res=dp[j];
                                pre[i]=j;
                            }
                        }
                    }
                    dp[i]=res+1;
                    if(dp[i]>ans)
                    {
                        index=i;
                        ans=dp[i];
                    }
                }
            }
            printf("%d\n",ans);
            if(ans==0)
            continue;
            int ct=0;
            st[ct++]=a[index].id;
            int cur=index;
            while(pre[cur]!=0)
            {
                st[ct++]=a[pre[cur]].id;
                cur=pre[cur];
            }
            for(i=ct-1;i>=0;i--)
            {
                printf("%d",st[i]);
                if(i!=0)
                printf(" ");
            }
            printf("\n");
        }
    }
    //

    CODEFORCES简单题       

           

  • 相关阅读:
    5.深入TiDB:Insert 语句
    4.深入TiDB:执行计划执行过程详解
    3.深入TiDB:执行优化讲解
    2.深入TiDB:入口代码分析及调试 TiDB
    1.深入TiDB:初见TiDB
    开发必备之单元测试
    如何用好MySQL索引
    SpringBoot运行源码剖析(一)
    深入理解Java虚拟机读后感
    Java并发编程艺术读后感
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215872.html
Copyright © 2011-2022 走看看