Codeforces Round #202 (Div. 2) B. Color the Fence
2016-09-26 01:18
387 查看
题目链接:传送门
题意,给出1-9的花费,n为总量,求出能用最多的花费(<=n)画出最大的数字。
贪心,网上找的比较好的代码。
先通过最小的花费求出最多的位数。然后遍历每位数,看看这个数上面能放最大的值是多少,保证在放上这个最大值之后剩余的总量除以最小花费(即放上这个值后假设后面每个都是那个最小花费)总位数要>=最多的位数。
代码如下:
“`
题意,给出1-9的花费,n为总量,求出能用最多的花费(<=n)画出最大的数字。
贪心,网上找的比较好的代码。
先通过最小的花费求出最多的位数。然后遍历每位数,看看这个数上面能放最大的值是多少,保证在放上这个最大值之后剩余的总量除以最小花费(即放上这个值后假设后面每个都是那个最小花费)总位数要>=最多的位数。
代码如下:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define N 10010000 int a[10]; int main(){ int i,j,n,m,k; while(scanf("%d",&n)!=EOF){ int Min=0xffffff; for(i=1;i<=9;i++) { cin>>a[i]; if(Min>a[i]) Min=a[i]; } if(n==0||Min>n){ cout<<"-1"<<endl; continue; } for(i=n/Min-1;i>=0;i--){ for(j=9;j>=1;j--){ if(n>=a[j]&&(n-a[j])/Min>=i){ n-=a[j]; cout<<j; break; } } } cout<<endl; } 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) 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) / ProblemSet 349B - B. Color the Fence 【贪心】
- Codeforces Round #202 (Div. 2)B. Color the Fence
- Codeforces Round #202 B:Color the Fence
- Codeforces Round #202 (Div. 2) (A、B、C、D)
- Codeforces Round #195 (Div. 2) B. Vasily the Bear and Fly - 找规律
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
- Codeforces Round #202 (Div. 2) A,B
- Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game
- Codeforces Round #250 (Div. 1) A. The Child and Toy
- Codeforces Round #250 (Div. 2)——The Child and Set
- Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle
- Codeforces Round #150 (Div. 2) C. The Brand New Function
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #163 (Div. 2) / 226A Stones on the Table (字符串处理)
- Codeforces Round #250 (Div. 1) D. The Child and Sequence