• Codeforces Round #284 (Div. 2)A B C 模拟 数学


    A. Watching a movie
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You have decided to watch the best moments of some movie. There are two buttons on your player:

    1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie.
    2. Skip exactly x minutes of the movie (x is some fixed positive integer). If the player is now at the t-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t + x).

    Initially the movie is turned on in the player on the first minute, and you want to watch exactly n best moments of the movie, the i-th best moment starts at the li-th minute and ends at the ri-th minute (more formally, the i-th best moment consists of minutes: li, li + 1, ..., ri).

    Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?

    Input

    The first line contains two space-separated integers n, x (1 ≤ n ≤ 50, 1 ≤ x ≤ 105) — the number of the best moments of the movie and the value of x for the second button.

    The following n lines contain the descriptions of the best moments of the movie, the i-th line of the description contains two integers separated by a space li, ri (1 ≤ li ≤ ri ≤ 105).

    It is guaranteed that for all integers i from 2 to n the following condition holds: ri - 1 < li.

    Output

    Output a single number — the answer to the problem.

    Examples
    Input
    2 3
    5 6
    10 12
    Output
    6
    Input
    1 1
    1 100000
    Output
    100000
    Note

    In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie.

    In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.

    题意:水 n个期望区间  可跳过x 问需要持续的最短时间

    题解:模拟 

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #define __int64 ll
     6 using namespace std;
     7 int n,k;
     8 int mp[100005];
     9 int l,r;
    10 int main()
    11 {
    12     scanf("%d %d",&n,&k);
    13     for(int i=1;i<=100000;i++)
    14         mp[i]=0;
    15     for(int i=1;i<=n;i++)
    16     {
    17         scanf("%d %d",&l,&r);
    18         for(int j=l;j<=r;j++)
    19         mp[j]=1;
    20     }
    21     int sum=0;
    22     int be=1;
    23     for(int i=1;i<=100000;i++)
    24     {
    25         int j=i;
    26         if(mp[j]==1)
    27         {
    28         sum=sum+(j-be)%k;
    29         int s;
    30          for( s=j;s<=100000;s++)
    31          {
    32              if(mp[s]==1)
    33                 sum++;
    34              else
    35                 break;
    36          }
    37          j=s;
    38          be=j;
    39         }
    40         i=j;
    41     }
    42     printf("%d
    ",sum);
    43     return 0;
    44 }
    B. Lecture
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.

    You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.

    You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.

    You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.

    Input

    The first line contains two integers, n and m (1 ≤ n ≤ 3000, 1 ≤ m ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages.

    The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.

    The next line contains n space-separated strings c1, c2, ..., cn — the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.

    All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.

    Output

    Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.

    Examples
    Input
    4 3
    codeforces codesecrof
    contest round
    letter message
    codeforces contest letter contest
    Output
    codeforces round letter round
    Input
    5 3
    joll wuqrd
    euzf un
    hbnyiyc rsoqqveh
    hbnyiyc joll joll euzf joll
    Output
    hbnyiyc joll joll un joll

    题意:string
    题解:模拟
     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<map>
     6 #define __int64 ll
     7 using namespace std;
     8 int n,m;
     9 string a,b;
    10 map<string,string> mp;
    11 int main()
    12 {
    13     scanf("%d %d",&n,&m);
    14     for(int i=1;i<=m;i++)
    15     {
    16         cin>>a>>b;
    17         if(a.size()<=b.size())
    18         {
    19         mp[a]=a;
    20         mp[b]=a;
    21         }
    22         else
    23         {
    24             mp[a]=b;
    25             mp[b]=b;
    26         }
    27     }
    28     for(int i=1;i<=n;i++)
    29     {
    30         cin>>a;
    31         cout<<mp[a]<<" ";
    32     }
    33     return 0;
    34 }
    C. Crazy Town
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.

    Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).

    Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.

    Input

    The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.

    The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.

    The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).

    Output

    Output the answer to the problem.

    Examples
    Input
    1 1
    -1 -1
    2
    0 1 0
    1 0 0
    Output
    2
    Input
    1 1
    -1 -1
    3
    1 0 0
    0 1 0
    1 1 -3
    Output
    2
    Note

    Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):

                    

    题意:给你起点与终点 以及n条直线将平面分成若干个块 问由起点到终点最少要经过几次跨越

    (两个块之间的跨越只能通过边)

    题解:数学  通过判断起点与终点相对与每一条的边的位置 若在不同侧 需要记录答案

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<map>
     6 #define ll __int64
     7 #define eps 1e-15
     8 using namespace std;
     9 ll x1,y1;
    10 ll x2,y2;
    11 int n;
    12 ll a[305],b[305],c[305];
    13 int main()
    14 {
    15     scanf("%I64d %I64d",&x1,&y1);
    16     scanf("%I64d %I64d",&x2,&y2);
    17     scanf("%d",&n);
    18     for(int i=1; i<=n; i++)
    19         scanf("%I64d %I64d %I64d",&a[i],&b[i],&c[i]);
    20     int sum=0;
    21     for(int i=1; i<=n; i++)
    22     {
    23         ll exm1;
    24         ll exm2;
    25         exm1=a[i]*x1+b[i]*y1+c[i];
    26         exm2=a[i]*x2+b[i]*y2+c[i];
    27         if(exm1>0)
    28             exm1=1;
    29         else
    30             exm1=0;
    31         if(exm2>0)
    32             exm2=1;
    33         else
    34             exm2=0;
    35         if(exm1^exm2==1)
    36             sum++;
    37     }
    38     cout<<sum<<endl;
    39     return 0;
    40 }
  • 相关阅读:
    silverlight重写TextBox PassWordBox
    android使用html开发
    SilverLight中DataGrid显示值转换
    STM32 GPIO 的配置与使用
    开始。。
    VCS使用指令
    【转】关闭 Windows 7中的 6to4 隧道
    DC中关于list、双引号和花括号的使用区别
    解决了microblaze在ISE中例化时自动插入IO buffer
    Recovery time 和 Removal time的概念
  • 原文地址:https://www.cnblogs.com/hsd-/p/6075570.html
Copyright © 2020-2023  润新知