Codeforces Round #202 (Div. 2)B. Color the Fence(贪心,模拟)
来源:互联网 发布:云端是什么软件 编辑:程序博客网 时间:2024/05/29 08:44
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.
Examples
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
题意:给你n元,构成数字1-9的花费为ai,问能组成的最大数字是多少。
题解:首先数字数越多越好,当数字数确定后,看能不能把将数字换成更大的。有点模拟的意思。
代码:
#include <bits/stdc++.h>#define ll long long#define bababba printf("!!!!!!!!!\n")using namespace std;int cnt;map<int,int>mp;const int N=1e7+10;int ans[N];struct node{ int id,pi; bool operator <(const node &t)const{ return pi<t.pi||(pi==t.pi&&id>t.id); }}a[100];void save(){ for(int i=1;i<=cnt;i++) { ans[i]=a[1].id; }}void print(){ for(int i=1;i<=cnt;i++) { printf("%d",ans[i]); } printf("\n");}int main(){ int n; scanf("%d",&n); for(int i=1;i<=9;i++) { int x; scanf("%d",&x); a[i].id=i; a[i].pi=x; } sort(a+1,a+10); for(int i=1;i<=9;i++) { mp[a[i].id]=i; } cnt=n/a[1].pi; if(cnt==0) { printf("-1\n"); return 0; } save(); if(n%a[1].pi==0) { print(); } else { int y=n%a[1].pi; for(int i=1;i<=cnt;i++) { for(int j=9;j>=1;j--) { if(y+a[mp[ans[i]]].pi>=a[mp[j]].pi&&j>ans[i])//j>ans[i]不加也能过,但我感觉是错的。。 { int t=ans[i]; ans[i]=j; y=y+a[mp[t]].pi-a[mp[j]].pi; break; } } } print(); } return 0;}
- Codeforces Round #202 (Div. 2)B. Color the Fence(贪心,模拟)
- Codeforces Round #202 (Div. 2) B. Color the Fence(贪心)
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - B. Color the Fence 【贪心】
- Codeforces Round #202 (Div. 2) B.Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2)B. Color the Fence
- Codeforces Round #202 (Div. 2)B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 B:Color the Fence
- CodeForces 349B Color the Fence (贪心)
- Codeforces 349 B Color the Fence (思维+贪心)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- 349B - Color the Fence (贪心)
- Codeforces 349B Color the Fence【贪心+思维】
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #428 (Div. 2)-贪心&模拟-B. Game of the Rows
- 一、隐式意图介绍
- Cookie
- View、SurfaceView、GLSurfaceView的关系
- Session
- c语言10个经典小程序
- Codeforces Round #202 (Div. 2)B. Color the Fence(贪心,模拟)
- 二阶魔方入门教程
- Android Studio 中 assets目录的使用
- $(window).load(function() {})和$(document).ready(function(){})的区别
- Android简单人品计算器
- UML电子商城(2)-首页功能及适配器的使用
- 段落排版--对齐
- 请介绍下Android中常用的五种布局
- XMLSchema validation error occured in: null ,line = 2, column = 1, Message = cvc-elt.1: Cannot find