YT04-貪心課後練習-1006—PAINTER(6.14日-煙臺大學ACM預備隊解題報告)
2709 PAINTER—計141 吳勝男
Description
Thelocal toy store sells smallfingerpaintingkits with between three and twelve 50ml bottles of paint, each a differentcolor. The paints are bright and fun to work with, and have the useful propertythat if you mix X ml each of any three different colors, you get X ml of gray.(The paints are thick and "airy", almost like cake frosting, and whenyou mix them together the volume doesn't increase, the paint just gets moredense.) None of the individual colors are gray; the only way to get gray is bymixing exactly three distinct colors, but it doesn't matter which three. Yourfriend Emily is an elementary school teacher and every Friday she does afingerpaintingproject with her class. Given the number of different colors needed, the amountof each color, and the amount of gray, your job is to calculate the number ofkits needed for her class.
The input consists of one or more test cases, followed by a linecontaining only zero that signals the end of the input. Each test case consistsof a single line of five or more integers, which are separated by a space. Thefirst integer N is the number of different colors (3 <= N <= 12).Following that are N different nonnegative integers, each at most 1,000, thatspecify the amount of each color needed. Last is a nonnegative integer G <=1,000 that specifies the amount of gray needed. All quantities are in ml.
For each test case, output the smallest number of fingerpaintingkits sufficient to provide the required amounts of all the colors and gray.Note that all grays are considered equal, so in order to find the minimumnumber of kits for a test case you may need to make grays using differentcombinations of three distinct colors.
3 40 95 21 0
7 25 60 400 250 0 60 0 500
4 90 95 75 95 10
4 90 95 75 95 11
5 0 0 0 0 0 333
0
2 8 2 3 4
每套顏料包3-12種顏料(沒有灰色),每種顏料50ml。任意取3種顏料(每種顏料x ml)混合即可得到x ml的灰色顏料(根據油漆的化學性質,不同顏色的油漆混合,體積不會增加,只會使油漆更加粘稠)。給定一套顏料包內顏料種類的數量,每種顏色的總量和所需灰色顏料的量。計算至少使用多少套顏料包。
輸入一個或多個測試資料,最後輸入0結束資料輸入。
每行測試資料包括5個或5個以上整數,用空格隔開。
每行第一個整數是顏色種類的數量,接下來的整數是
每種顏色需要的量(均小於1000ml),每行最後一個數代表所需灰色的量,單位為ml.
問題解決思路:
#include <iostream>
using namespace std;
int main()
{
int colorNum;
cin >> colorNum;
while(colorNum!=0)
{
int grayNum;
int* color=new int[colorNum];
int kitsNum;
for(int i=0; i<colorNum; i++)
cin >> color[i];
cin >> grayNum;
int max=0;
for(int i=0; i<colorNum; i++)
{
if(max < color[i])
max = color[i];
}
kitsNum =max/50+(max%50==0?0:1);
int temp=kitsNum*50;
for(int i=0; i<colorNum; i++)
color[i]=temp-color[i];
while(grayNum!=0)
{
int max1=0,max2=1,max3=2;//最大的三個數的位置
for(int i=3; i<colorNum; i++)
{
if(color[i] > color[max1])
max1 = i;
else if(color[i] > color[max2])
max2 = i;
else if(color[i] > color[max3])
max3 = i;
}
if(color[max1]>0 && color[max2]!=0 && color[max3]!=0)
{
color[max1]--;
color[max2]--;
color[max3]--;
grayNum--;
}
else
{
kitsNum++;
for(int i=0; i<colorNum; i++)
color[i]+=50;
}
}
cout << kitsNum << endl;
cin >> colorNum;
}
}
相關文章
- YT04-貪心課後練習-1004—迷瘴-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課後練習-1002—Repair the Wall-(6.14日-煙臺大學ACM預備隊解題報告)AIACM
- YT04-貪心課堂練習-1004—Fire Net-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課堂練習-1005—Wooden Sticks-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課堂練習-1001 今年暑假不AC-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT04-貪心課後練習-1003—悼念512汶川大地震遇難同胞——老人是真餓了-(6.14日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課後題目-1006 不容易系列之(4)——考新郎-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課後題目-1001 母牛的故事-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課後題目-1004—Max Sum -(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課後題目-1002 超級樓梯-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課堂題目-1001 蟠桃記-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT06-揹包-1001—Bone Collector -(6.27日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課後題目-1003—免費餡餅 -(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課堂題目-1005 Children’s Queue-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課後題目-1001—FatMouse's Speed-(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課堂題目-1002 折線分割平面-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課堂題目-1003—數塔-(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課堂題目-1004 不容易系列之一-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課後題目-1002—Super Jumping! Jumping! Jumping! -(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT06-揹包-1002—Piggy-Bank -(6.27日-煙臺大學ACM預備隊解題報告)ACM
- YT05-動態歸劃求解課堂題目-1004—最少攔截系統-(6.21日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課後題目-1003 不容易系列之(3)—— LELE的RPG難題-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT03-遞推求解課堂題目-1003 獻給杭電五十週年校慶的禮物-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- YT06-揹包-1003—悼念512汶川大地震遇難同胞——珍惜現在,感恩生活 -(6.27日-煙臺大學ACM預備隊解題報告)ACM
- 河南理工大學程式設計(ACM)大賽解題報告程式設計ACM
- 課後練習
- 杭電ACM hdu 2079 選課時間 解題報告(母函式)ACM函式
- [Offer收割]程式設計練習賽1 hihocoder 1271 艦隊遊戲 (狀態壓縮+貪心 好題)程式設計遊戲
- 牛客練習賽40 B 小A與任務(貪心)
- 反悔貪心雜題
- acm訓練題ACM
- NYNU ACM 藍橋杯選拔賽 解題報告ACM
- 山東省第四屆acm解題報告(部分)ACM
- 大學畢業課題研究開題報告PPT分享-20套可下載
- 貪心 做題筆記筆記
- 「貪心」做題記錄
- [uoj228]基礎資料結構練習題 解題報告資料結構
- ACM日常訓練日記——7.25ACM