ZOJ 3657The Little Girl..2012長春現場賽C題(簡單思維+細心)
It's yet another festival season in Gensokyo. Little girl Alice planned to pick mushrooms in five mountains. She brought five bags with her and used different bags to collect mushrooms from different mountains. Each bag has a capacity of 2012 grams. Alice has finished picking mushrooms in 0 ≤ n ≤ 5 mountains. In the the i-th mountain, she picked 0 ≤ wi ≤ 2012 grams of mushrooms. Now she is moving forward to the remained mountains. After finishing picking mushrooms in all the five mountains, she want to bring as much mushrooms as possible home to cook a delicious soup.
Alice lives in the forest of magic. At the entry of the forest of magic, lives three mischievous fairies, Sunny, Lunar and Star. On Alice's way back home, to enter the forest, she must give them exactly three bags of mushrooms whose total weight must be of integral kilograms. If she cannot do so, she must leave all the five bags and enter the forest with no mushrooms.
Somewhere in the forest of magic near Alice's house, lives a magician, Marisa. Marisa will steal 1 kilogram of mushrooms repeatedly from Alice until she has no more than 1 kilogram mushrooms in total.
So when Alice get home, what's the maximum possible amount of mushrooms Alice has? Remember that our common sense doesn't always hold in Gensokyo. People in Gensokyo belive that 1 kilograms is equal to 1024 grams.
Input
There are about 8192 test cases. Process to the end of file.
The first line of each test case contains an integer 0 ≤ n ≤ 5, the number of mountains where Alice has picked mushrooms. The second line contains n integers 0 ≤ wi ≤ 2012, the amount of mushrooms picked in each mountain.
Output
For each test case, output the maximum possible amount of mushrooms Alice can bring home, modulo 20121014 (this is NOT a prime).
Sample Input
1 9 4 512 512 512 512 5 100 200 300 400 500 5 208 308 508 708 1108
Sample Output
1024 1024 0 792
Note
In the second sample, if Alice doesn't pick any mushrooms from the 5-th mountain. She can give (512+512+0)=1024 grams of mushrooms to Sunny, Lunar and Star. Marisa won't steal any mushrooms from her as she has exactly 1 kilograms of mushrooms in total.
In the third sample, there are no three bags whose total weight is of integral kilograms. So Alice must leave all the five bags and enter the forest with no mushrooms.
In the last sample:
- Giving Sunny, Lunar and Star: (208+308+508)=1024
- Stolen by Marisa: ((708+1108)-1024)=792
感受:PI隊在十分鐘內就直接A了這題,當時我在看B題,是關於矩陣&|位運算的。小吉吉當時在看C題,但是看了十幾分鐘沒看懂,博博準備敲K題。我跟吉吉就一起看了C題,博博敲了,交上去是TLE,然後想著怎麼節省時間打表或者直接算對數取最接近的值列舉。結果是我們把資料看錯了,紙上是1012顯示不了10^12.瞬間有種崩潰的感覺。。吉吉決定寫C題,但是交上去了卻WA了,然後他就判斷可以給0,還是WA。然後我們就別的題目都不看了,專心搞這兩個。這兩題都是最後二十分鐘A的,太驚險了。覺得我們還是交流地不是很到位。不過BME的實力還是很大的。
題目大意:給你n(0~5)個數,總共有五堆數,前n堆確定。後面的可以可以任意取。需要找出三堆模上1024給別人,找不出來輸出0,。自己留下兩堆,然後兩堆之和大於1024全部是別人的。主要是判0的情況。
解題思路:如果n<=3,直接輸出1024.如果n==4,先找三堆能不能組成1024的倍數,注意可以是0,如果可以直接輸出1024.如果不能找出4堆裡面兩堆之和最大的,注意0與1024的轉變。n==5的時候找三堆看是否能組成1024的倍數,注意可以是0.然後另兩堆最大的,注意0與1024的轉變。
題目地址:The Little Girl who Picks Mushrooms
AC程式碼:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
int a[8],n,sum,ans;
int main()
{
int i,j;
while(~scanf("%d",&n))
{
sum=0,ans=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(n<=3)
puts("1024");
else if(n==4)
{
int flag=0;
for(i=1;i<=4;i++) //3個之和可以組成1024倍數
if((sum-a[i])%1024==0) //可以給0
{
flag=1;
break;
}
if(flag) puts("1024");
else
{
int tmp;
for(i=1;i<=3;i++)
for(j=i+1;j<=4;j++)
{
tmp=a[i]+a[j];
if(tmp) //自己拿到的0不能直接變成1024
{
tmp%=1024;
if(tmp==0) tmp=1024;
}
if(ans<tmp) ans=tmp;
}
printf("%d\n",ans);
}
}
else //n為5
{
int tmp;
for(i=1;i<=4;i++)
for(j=i+1;j<=5;j++)
{
int t=sum-a[i]-a[j];
if(t%1024==0) //可以給0
{
tmp=a[i]+a[j];
if(tmp) //自己拿到的0不能直接變成1024
{
tmp%=1024;
if(tmp==0) tmp=1024;
}
if(ans<tmp) ans=tmp;
}
}
printf("%d\n",ans);
}
}
return 0;
}
相關文章
- 牛客練習賽26 C 城市規劃【思維+貪心】
- Find the Maximum - 題解【思維,貪心】
- 記一個簡單的sql題:思維擴散SQL
- ZOJ Monthly, January 2019 - A Little Sub and Pascal's Triangle(找規律)
- 貪心(入門簡單題)
- CCPC 2020 長春站 部分簡略題解
- Leetcode第 217 場周賽(思維量比較大)LeetCode
- spring思維導圖,讓spring更加簡單易懂Spring
- 挑選方案問題(牛客競賽 思維題+推導公式)公式
- C++奧賽一本通貪心題解C++
- ZOJ——Copying Books 最大值最小化問題 (貪心 + 二分)
- 力扣896. 單調數列-C語言實現-簡單題力扣C語言
- ZOJ2019年1月月賽
- Independence[ARC099C][思維]
- 思維鏈?思維樹?華為諾亞:現在到了思維森林時刻!
- 思維導圖的簡單畫法有人知道嗎?求分享
- C語言陣列實現約瑟夫環出圈問題 程式碼詳細註釋 簡單易懂C語言陣列
- 場上過不去的簡單題
- 【C/C++】ghost ddl指令碼簡單實現C++指令碼
- vue載入更多,上拉重新整理 VueScroller 簡單化思維Vue
- OI常見思維方式1(簡單/特殊情形——數學相關)
- 簡單的素數問題(C++)C++
- 力扣566. 重塑矩陣-C語言實現-簡單題力扣矩陣C語言
- 2017第八屆天梯賽省賽C++C組【第一題:貪吃蛇長度】C++
- python 爬蟲 mc 皮膚站 little skin 的簡單爬取Python爬蟲
- zoj-4053(2018ICPC青島網路賽K題)啟發式分裂
- NSArray 簡單細說
- 組合計數思維題
- 好玩的木樁(思維題)
- 思維題專項訓練
- 長春開票-長春開票
- 思維體系---技術思維、業務資料思維、產品思維、複合思維
- [無心插柳]簡單實現常用的表單校驗函式函式
- zoj
- 【思維導圖-索引篇】搞定資料庫索引就是這麼簡單索引資料庫
- 簡單好用的思維導圖:MindNode 2023 啟用中文版最新
- tcp 實現簡單http 問題TCPHTTP
- 長春哪開票-長春開票
- 2020CCPC長春站部分題解