A. Cinema Line
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?

Input

The first line contains integer n (1≤n≤105) — the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.

Output

Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".

Sample test(s)
input

4
25 25 50 50

output

YES

input

2
25 100

output

NO

input

4
50 50 25 25

output

NO

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int ershiwu,wushi,n,money;

int main()
{
    ershiwu=0,wushi=0;
    scanf("%d",&n);
    bool flag=true;
    while(n--)
    {
        scanf("%d",&money);
        if(money==25)
            ershiwu++;
        else if(money==50)
        {
            if(ershiwu-1>=0)
            {
                ershiwu--;
                wushi++;
            }
            else
            {
                flag=false; break;
            }
        }
        else if(money==100)
        {
            if(wushi>=1&&ershiwu>=1)
            {
                wushi--; ershiwu--;
            }
            else if(ershiwu>=3)
            {
                ershiwu-=3;
            }
            else
            {
                flag=false;break;
            }
        }
    }
    if(flag)
        puts("YES");
    else
        puts("NO");

return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

B. Color the Fence
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.

Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requires ad liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.

Help Igor find the maximum number he can write on the fence.

Input

The first line contains a positive integer v (0≤v≤106). The second line contains nine positive integers a1,a2,...,a9 (1≤ai≤105).

Output

Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.

Sample test(s)
input

5
5 4 3 2 1 2 3 4 5

output

55555

input

2
9 11 1 12 5 8 9 10 6

output

33

input

0
1 1 1 1 1 1 1 1 1

output

-1

先保证位数最大,然后使用余数尽量升级成大的数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct nim
{
    int valu;
    int cost;
    int deta;
}a[10];

bool cmp(nim a,nim b)
{
    if(a.cost!=b.cost)
    {
        return a.cost<b.cost;
    }
    else return a.valu>b.valu;
}

bool cmp2(nim a,nim b)
{
    if(a.valu!=b.valu)
    {
        return a.valu>b.valu;
    }
    else
    {
        return a.cost<b.cost;
    }
}

int number[12];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<9;i++)
    {
        a.valu=i+1;
        scanf("%d",&a.cost);
    }
    sort(a,a+9,cmp);

if(n<a[0].cost)
    {
        puts("-1");
        return 0;
    }

memset(number,0,sizeof(number));
    int number1=n/a[0].cost;
    int res=n%a[0].cost;
    number[a[0].valu]=number1;
    a[0].deta=0;
if(res!=0)
{
    for(int i=1;i<9;i++)
    {
        a.deta=a.cost-a[0].cost;
    }

sort(a+1,a+9,cmp2);

for(int i=1;i<9;i++)
    {
   //     printf("%d %d\n",a.valu,a.deta);
        if(a.valu>a[0].valu)
        while(res>=0)
        {
            if(res-a.deta<0) break;
            res-=a.deta;
            if(number[a[0].valu]-1>=0)
            {
                number[a[0].valu]--;
                number[a.valu]++;
            }
            else
            {
                break;
            }
        }
    }
}
    bool flag=false;
    for(int i=9;i>=1;i--)
    {
        while(number)
        {
            flag=true;
            printf("%d",i);
            number--;
        }
    }
    if(flag==false)
        printf("-1");
    putchar(10);
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

Codeforces Round #202 (Div. 2) A,B的更多相关文章

  1. Codeforces Round #202 (Div. 2)

    第一题水题但是wa了一发,排队记录下收到的25,50,100,看能不能找零,要注意100可以找25*3 复杂度O(n) 第二题贪心,先找出最小的花费,然后就能得出最长的位数,然后循环对每个位上的数看能 ...

  2. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

  3. Codeforces Round #202 (Div. 1) A. Mafia 推公式 + 二分答案

    http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory limit p ...

  4. Codeforces Round #202 (Div. 1) D. Turtles DP

    D. Turtles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/problem/B ...

  5. Codeforces Round #202 (Div. 2) B,C,D,E

    贪心 B. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #633 (Div. 2)

    Codeforces Round #633(Div.2) \(A.Filling\ Diamonds\) 答案就是构成的六边形数量+1 //#pragma GCC optimize("O3& ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. 几个pointer

    [备份]了解initramfs,越往深处走觉着需要了解的东西越多,所以干脆回来,从实际系统的实现开始寻迹.在学习的这个系统中,里面用了busybox,实现的系统可谓精简之又精简.早上主要学习了root ...

  2. MongoDB安装,配置

    安装 cd /usr/local/srcwget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.6.tgztar z ...

  3. 让AutoMapper更好用

    AutoMapper Dto与EF实体之间的转换用AutoMapper会变的很方便.很高效,是大多数项目的选择.博主本人的项目也在使用AutoMapper这个组件 好用归好用,但是想要把它用好又是另一 ...

  4. android开发中遇到的各种问题收集--不定期更新

    以下问题都是自己在开发中亲身碰到的 ,在这里留个备份,方便下次查阅. 1.java.lang.IllegalStateException ,Cannot execute task: the task ...

  5. 连续赋值与求值顺序var a = {n:1};a.x = a = {n:2}; alert(a.x);

    代码如下: <script> var a = {n:1}; var b = a; a.x = a = {n:2}; console.log(a.x);// --> undefined ...

  6. JSP内置对象-request

    JSP内置对象即无需声明就可以直接使用的对象实例,在实际的开发过程中,比较常用的JSP对象有request,response,session,out和application等,笔者在本文章中将简单介绍 ...

  7. nginx跨域设置

    nginx跨域问题例子:访问http://10.0.0.10/ 需要能实现跨域 操作:http://10.0.0.10/项目是部署在tomcat里面,tomcat跨域暂时还不会,按照网上的方法操作也没 ...

  8. 2-SAT 问题

    2-SAT 问题是k-SAT问题在k==2时的特殊情况,因为已经证明k>=3时的k-sat问题属于npc问题.所以在这里仅研究2-SAT的特殊情况.   何为2-sat问题? 简单地说就是有N个 ...

  9. java8 中的时间和数据的变化

    java8除了lambda表达式之外还对时间和数组这两块常用API做想应调整, Stream 有几个常用函数: store 排序 (a,b)-> a.compareTo(b)  排出来的结果是正 ...

  10. 转:遗传算法解决TSP问题

    1.编码 这篇文章中遗传算法对TSP问题的解空间编码是十进制编码.如果有十个城市,编码可以如下: 0 1 2 3 4 5 6 7 8 9 这条编码代表着一条路径,先经过0,再经过1,依次下去. 2.选 ...