程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #241 (Div. 2) A~C

Codeforces Round #241 (Div. 2) A~C

編輯:C++入門知識


全是水題。。。。又在浪費生命。。。。

A. Guess a number! time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.

The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:

  • Is it true that y is strictly larger than number x?
  • Is it true that y is strictly smaller than number x?
  • Is it true that y is larger than or equal to number x?
  • Is it true that y is smaller than or equal to number x?

    On each question the host answers truthfully, "yes" or "no".

    Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".

    Input

    The first line of the input contains a single integer n (1?≤?n?≤?10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:

    • ">" (for the first type queries),
    • "<" (for the second type queries),
    • ">=" (for the third type queries),
    • "<=" (for the fourth type queries).

      All values of x are integer and meet the inequation ?-?109?≤?x?≤?109. The answer is an English letter "Y" (for "yes") or "N" (for "no").

      Consequtive elements in lines are separated by a single space.

      Output

      Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation ?-?2·109?≤?y?≤?2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).

      Sample test(s) input
      4
      >= 1 Y
      < 3 N
      <= -3 N
      > 55 N
      
      output
      17
      
      input
      2
      > 100 Y
      < -100 Y
      
      output
      Impossible

      #include 
      #include 
      #include 
      #include 
      #include 
      
      using namespace std;
      
      long long int low,high;
      
      int main()
      {
          int n;
          long long int num;
          string type,re;
          cin>>n;
          low=-1e9-10;
          high=1e9+10;
      
          for(int i=0;i>type>>num>>re;
              if(type==">")
              {
                  if(re=="Y") low=max(low,num+1);
                  else high=min(high,num);
              }
              else if(type==">=")
              {
                  if(re=="Y") low=max(low,num);
                  else high=min(high,num-1);
              }
              else if(type=="<")
              {
                  if(re=="Y") high=min(high,num-1);
                  else low=max(low,num);
              }
              else if(type=="<=")
              {
                  if(re=="Y") high=min(high,num);
                  else low=max(low,num+1);
              }
          }
          if(high>=low)
              cout<<(high+low)/2<

      B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

      A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.

      Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these n colors. Adding the j-th color to the i-th picture takes the j-th painter tij units of time.

      Order is important everywhere, so the painters' work is ordered by the following rules:

      • Each picture is first painted by the first painter, then by the second one, and so on. That is, after the j-th painter finishes working on the picture, it must go to the (j?+?1)-th painter (if j?n);
      • each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on;
      • each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest;
      • as soon as the j-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter.

        Given that the painters start working at time 0, find for each picture the time when it is ready for sale.

        Input

        The first line of the input contains integers m,?n (1?≤?m?≤?50000,?1?≤?n?≤?5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1,?ti2,?...,?tin (1?≤?tij?≤?1000), where tijis the time the j-th painter needs to work on the i-th picture.

        Output

        Print the sequence of m integers r1,?r2,?...,?rm, where ri is the moment when the n-th painter stopped working on the i-th picture.

        Sample test(s) input
        5 1
        1
        2
        3
        4
        5
        
        output
        1 3 6 10 15 
        input
        4 2
        2 5
        3 1
        5 3
        10 1
        
        output
        7 8 13 21 


        #include 
        #include 
        #include 
        #include 
        
        using namespace std;
        
        int m,n;
        int t[55000][7];
        int time[2][55000];
        
        int main()
        {
            scanf("%d%d",&m,&n);
            for(int i=1;i<=m;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    scanf("%d",&t[i][j]);
                }
            }
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    time[i%2][j]=max(time[i%2][j-1]+t[j][i],time[(i-1)%2][j]+t[j][i]);
                }
            }
            for(int i=1;i<=m;i++)
                printf("%d ",time[n%2][i]);
            return 0;
        }
        


        C. Booking System time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

        Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!

        A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.

        There are n booking requests received by now. Each request is characterized by two numbers: ci and pi — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.

        We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.

        Unfortunately, there only are k tables in the restaurant. For each table, we know ri — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.

        Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.

        Input

        The first line of the input contains integer n (1?≤?n?≤?1000) — the number of requests from visitors. Then n lines follow. Each line contains two integers: ci,?pi (1?≤?ci,?pi?≤?1000) — the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.

        The next line contains integer k (1?≤?k?≤?1000) — the number of tables in the restaurant. The last line contains k space-separated integers: r1,?r2,?...,?rk (1?≤?ri?≤?1000) — the maximum number of people that can sit at each table.

        Output

        In the first line print two integers: m,?s — the number of accepted requests and the total money you get from these requests, correspondingly.

        Then print m lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input.

        If there are multiple optimal answers, print any of them.

        Sample test(s) input
        3
        10 50
        2 100
        5 30
        3
        4 6 9
        
        output
        2 130
        2 1
        3 2


        #include 
        #include 
        #include 
        #include 
        
        using namespace std;
        
        int n,m;
        struct VS
        {
            int c,p,id,tb;
        }vit[1100];
        
        bool cmp(VS a,VS b)
        {
            if(a.p!=b.p) return a.p>b.p;
            return a.cmxpeople) continue;
                for(int j=0;jr[j].cp) continue;
                    if(r[j].tk==0)
                    {
                        r[j].tk=1;
                        vit[i].tb=r[j].id;
                        ans++; sum+=vit[i].p;
                        break;
                    }
                }
            }
            cout<






  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved