zoukankan      html  css  js  c++  java
  • CF349 B. Color the Fence

    题目传送门:https://codeforces.com/problemset/problem/349/B

    题目大意:
    给你总颜料数(v),再给你9个数(a_{1...9})(a_i)表示画(i)的颜料消耗,求所能画出的最大的数


    要考虑画的数最大,首先得看位数,位数 (len) 可以用 $lfloor frac{v}{Min} floor $确定,而 (Min=min{a_i})

    得到位数后,我们从高位,从大数开始

    如果 (lfloorfrac{v-a_i}{Min} floor=len-1) ,则说明该位可填,否则不行

    /*program from Wolfycz*/
    #include<map>
    #include<cmath>
    #include<cstdio>
    #include<vector>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define Fi first
    #define Se second
    #define ll_inf 1e18
    #define MK make_pair
    #define sqr(x) ((x)*(x))
    #define pii pair<int,int>
    #define int_inf 0x7f7f7f7f
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline char gc(){
    	static char buf[1000000],*p1=buf,*p2=buf;
    	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
    }
    template<typename T>inline T frd(T x){
    	int f=1; char ch=gc();
    	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')    f=-1;
    	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<1)+(x<<3)+ch-'0';
    	return x*f;
    }
    template<typename T>inline T read(T x){
    	int f=1; char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
    	return x*f;
    }
    inline void print(int x){
    	if (x<0)	putchar('-'),x=-x;
    	if (x>9)	print(x/10);
    	putchar(x%10+'0');
    }
    const int N=10;
    int A[N+10];
    int main(){
    //	freopen(".in","r",stdin);
    //	freopen(".out","w",stdout);
    	int v=read(0),Min=int_inf;
    	for (int i=1;i<10;i++)	A[i]=read(0),Min=min(Min,A[i]);
    	if (v<Min){
    		printf("-1
    ");
    		return 0;
    	}
    	int Cnt=v/Min;
    	while (Cnt--){
    		for (int i=9;i;i--){
    			if (v>=A[i]&&(v-A[i])/Min==Cnt){
    				printf("%d",i);
    				v-=A[i];
    				break;
    			}
    		}
    	}
    	putchar('
    ');
    	return 0;
    }
    
    作者:Wolfycz
    本文版权归作者和博客园共有,欢迎转载,但必须在文章开头注明原文出处,否则保留追究法律责任的权利
  • 相关阅读:
    深入理解JavaScript的闭包特性 如何给循环中的对象添加事件
    兼容低版本浏览器的getElementByClassName方法
    印象深刻的bug
    pyinstaller将python编写的打卡程序打包成exe
    自动化环境搭建遇到问题
    VS2010带不出System.Data.OracleClient这个引用的解决方案
    迭代与列表生成式、生成器
    Python函数
    Python基础
    python+Selenium 环境搭建
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/14958378.html
Copyright © 2011-2022 走看看