日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nyoj 791 Color the fence(贪心)

發(fā)布時(shí)間:2025/3/16 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nyoj 791 Color the fence(贪心) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Color the fence

時(shí)間限制:1000?ms ?|? 內(nèi)存限制:65535?KB 難度:2 描述

Tom?has?fallen?in?love?with?Mary.?Now?Tom?wants?to?show?his?love?and?write?a?number?on?the?fence?opposite?to?

Mary’s?house.?Tom?thinks?that?the?larger?the?numbers?is,?the?more?chance?to?win?Mary’s?heart?he?has.

Unfortunately,?Tom?could?only?get?V?liters?paint.?He?did?the?math?and?concluded?that?digit?i?requires?ai?liters?paint.?

Besides,Tom?heard?that?Mary?doesn’t?like?zero.That’s?why?Tom?won’t?use?them?in?his?number.

Help?Tom?find?the?maximum?number?he?can?write?on?the?fence.

輸入
There are multiple test cases.
Each case the first line contains a nonnegative integer V(0≤V≤10^6).
The second line contains nine positive integers a1,a2,……,a9(1≤ai≤10^5).
輸出
Printf the maximum number Tom can write on the fence. If he has too little paint for any digit, print -1.
樣例輸入
55 4 3 2 1 2 3 4 529 11 1 12 5 8 9 10 6
樣例輸出
5555533


解題思路:

首先要肯定一點(diǎn),數(shù)字位數(shù)越多,肯定會(huì)越大。所以這里可以采用貪心的思想,假設(shè)最小的顏料的用量為min,那么最長的位數(shù)可以達(dá)到V / min,接下來我們就枚舉每一位可能的數(shù)字即可。這里還需要考慮,取了某一個(gè)數(shù)后,剩下的是否還可以保證最大。。

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int a[10]; int main() {int n;while(~scanf("%d", &n)){int Min = 0x3f3f3f3f;for(int i = 1; i < 10; i++){scanf("%d", &a[i]);Min = min(Min, a[i]);}if(n < Min){puts("-1");continue;}for(int i = n/Min-1; i >= 0; i--){for(int j = 9; j > 0; j--){if(n >= a[j] && (n - a[j])/Min >= i) //保證去了j之,還可以最長。。{printf("%d", j);n -= a[j];break;}}}puts("");}return 0; }

總結(jié)

以上是生活随笔為你收集整理的nyoj 791 Color the fence(贪心)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。