• 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;
    
    }
    
     
  • 相关阅读:
    ES6学习笔记<一> let const class extends super
    js_字符转Unicode
    (转)利用 SVG 和 CSS3 实现有趣的边框动画
    事件委托
    模拟操作
    jQUery动画
    jQUery事件
    jQuery的单选,复选,下拉
    jQuery中对属性的增删改查
    jQuery中其他
  • 原文地址:https://www.cnblogs.com/HackHer/p/6084652.html
Copyright © 2020-2023  润新知