• Codeforces Round #299 (Div. 2)A B C 水 dfs 二分


    A. Tavas and Nafas
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.

    His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.

    He ate coffee mix without water again, so right now he's really messed up and can't think.

    Your task is to help him by telling him what to type.

    Input

    The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.

    Output

    In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.

    Examples
    Input
    6
    Output
    six
    Input
    99
    Output
    ninety-nine
    Input
    20
    Output
    twenty
    Note

    You can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals .

    题意:将0~99转换为单词表示

    题解:标记一下。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll __int64
     4 int n;
     5 map<int,string> mp;
     6 int main()
     7 {
     8     scanf("%d",&n);
     9     mp[0]="zero";
    10     mp[1]="one";
    11     mp[2]="two";
    12     mp[3]="three";
    13     mp[4]="four";
    14     mp[5]="five";
    15     mp[6]="six";
    16     mp[7]="seven";
    17     mp[8]="eight";
    18     mp[9]="nine";
    19     mp[10]="ten";
    20     mp[11]="eleven";
    21     mp[12]="twelve";
    22     mp[13]="thirteen";
    23     mp[14]="fourteen";
    24     mp[15]="fifteen";
    25     mp[16]="sixteen";
    26     mp[17]="seventeen";
    27     mp[18]="eighteen";
    28     mp[19]="nineteen";
    29     mp[20]="twenty";
    30     mp[30]="thirty";
    31     mp[40]="forty";
    32     mp[50]="fifty";
    33     mp[60]="sixty";
    34     mp[70]="seventy";
    35     mp[80]="eighty";
    36     mp[90]="ninety";
    37     if(n<=20)
    38         cout<<mp[n]<<endl;
    39     else
    40     {
    41         int a,b;
    42         a=n/10;
    43         b=n%10;
    44         if(b>0)
    45         cout<<mp[a*10]<<"-"<<mp[b]<<endl;
    46         else
    47         cout<<mp[a*10]<<endl;
    48     }
    49     return 0;
    50 }
    B. Tavas and SaDDas
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

    The problem is:

    You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

    If we sort all lucky numbers in increasing order, what's the 1-based index of n?

    Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

    Input

    The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).

    Output

    Print the index of n among all lucky numbers.

    Examples
    Input
    4
    Output
    1
    Input
    7
    Output
    2
    Input
    77
    Output
    6
    题意:求小于等于的n的数中 只含有4,7的数字的个数
    题解:dfs一下
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll __int64
     4 ll n;
     5 ll sum=0;
     6 void dfs(ll x)
     7 {
     8     if(x<=n)
     9         sum++;
    10     else
    11         return ;
    12     dfs(x*10+7);
    13     dfs(x*10+4);
    14 }
    15 int main()
    16 {
    17     scanf("%I64d",&n);
    18     dfs(4);
    19     dfs(7);
    20     printf("%I64d
    ",sum);
    21     return 0;
    22 }
    C. Tavas and Karafs
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

    Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.

    For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.

    Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.

    Input

    The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).

    Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.

    Output

    For each query, print its answer in a single line.

    Examples
    Input
    2 1 4
    1 5 3
    3 3 10
    7 10 2
    6 4 8
    Output
    4
    -1
    8
    -1
    Input
    1 5 2
    1 5 10
    2 7 4
    Output
    1
    2
    题意:一个很迷的题意 有一个等差数列  从A开始  公差为B  然后n个询问  每个询问给定l,t,m   然后要求如果每次可以最多选择m个数   使这m个数-1   那么在t次操作中可以使l为左端点的最长序列中使所有数为0  输出这个最长序列的右端序号
    题解: 序列h1,h2,...,hn 可以在t次时间内(每次至多让m个元素减少1)  全部减小为0  当且仅当 max(h1, h2, ..., hn) <= t  &&  h1 + h2 + ... + hn <= m*t   
    二分右端点;
     
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll __int64
     4 ll a,b,n;
     5 ll l,t,m;
     6 bool fun(int x)
     7 {
     8     ll shou=a+(l-1)*b;
     9     ll exm=a+(x-1)*b;
    10     ll sum=(shou+exm)*(x-l+1)/2;
    11     if(exm<=t&&sum<=t*m)
    12         return true;
    13     else
    14         return false;
    15 }
    16 int main()
    17 {
    18     scanf("%I64d %I64d %I64d",&a,&b,&n);
    19     for(int i=1;i<=n;i++)
    20     {
    21         scanf("%I64d %I64d %I64d",&l,&t,&m);
    22         ll left=l,right=1e6+1,mid;
    23         ll flag=0;
    24         while(left<=right)
    25         {
    26            mid=(left+right)/2;
    27            if(fun(mid)){
    28             left=mid+1;
    29             flag=1;
    30             }
    31            else
    32             right=mid-1;
    33         }
    34         if(flag==0)
    35             printf("-1
    ");
    36         else
    37         printf("%I64d
    ",right);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    现代软件工程第一次结对编程(黄金点游戏)总结
    现代软件工程第一周博客作业
    最后一周总结
    阅读和提问作业3 (期中作业)
    软件工程作业 案例分析
    第二次结对编程
    现代软件工程 结对编程总结
    现代软件工程 第一周 博客作业
    阅读作业
    Judy Beta 第三天
  • 原文地址:https://www.cnblogs.com/hsd-/p/6771095.html
Copyright © 2020-2023  润新知