zoukankan      html  css  js  c++  java
  • poj2709 解题报告

    #include <stdio.h>
    
    #include "malloc.h"
    
    //#include <mm_malloc.h>
    
    #include <stdlib.h>
    
     
    
    int *needPaint;
    
    int *leftPaint;
    
    int colorType;
    
    int graySize;
    
     
    
    int cmp(const void *p,const void *q)
    
    {
    
        return *(int*)p<*(int*)q?1:-1;
    
    }
    
     
    
    int kitN(){
    
     
    
        int k;
    
        int j;
    
        int currentKit = 0;
    
        
    
        qsort(needPaint,colorType ,sizeof(int),cmp);
    
        if(needPaint[0]%50==0)
    
            currentKit =needPaint[0]/50;
    
        else
    
            currentKit = needPaint[0]/50+1;
    
        
    
        
    
        for(j=0;j<colorType;j++){
    
            leftPaint[j] = currentKit*50-needPaint[j];
    
        }
    
        while(graySize>0){
    
           qsort(leftPaint,colorType ,sizeof(int),cmp);
    
            if(leftPaint[2]==0){
    
                currentKit++;
    
                for(k=0;k<colorType;k++){
    
                    leftPaint[k] += 50;
    
                }
    
                graySize--;
    
            }else{
    
            graySize--;
    
            leftPaint[0]--;
    
            leftPaint[1]--;
    
            leftPaint[2]--;
    
            qsort(leftPaint,colorType ,sizeof(int),cmp);
    
            }
    
        }
    
        
    
        return currentKit;
    
    }
    
     
    
    int main() {
    
        while(scanf("%d",&colorType) && colorType){
    
            int i;
    
            
    
            needPaint = (int*)malloc(sizeof(int)*(colorType));
    
            leftPaint =(int*)malloc(sizeof(int)*(colorType));
    
            
    
            for(i=0;i<colorType;i++){
    
                scanf("%d",&needPaint[i]);
    
            }
    
            scanf("%d",&graySize);
    
            
    
            printf("%d
    ",kitN());
    
        }
    
        
    
        return 0;
    
    }
    
     
  • 相关阅读:
    spring boot所有配置
    Hibernate validator的一些额外特性
    相似序列搜索
    时间序列异常检测
    基于结构的距离度量
    jupyterlab的启动404error问题
    爬虫-Chrome-问题1
    厘清重要概念的内涵与外延
    六)定时任务持久化
    公钥私钥
  • 原文地址:https://www.cnblogs.com/HackHer/p/6084652.html
Copyright © 2011-2022 走看看