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;
}
相關文章
- 簡單物聯網思維
- zoj 3811||牡丹江網賽 c題 並查集並查集
- 記一個簡單的sql題:思維擴散SQL
- HDU 4422 The Little Girl who Picks Mushrooms(簡單題)OOM
- 貪心(入門簡單題)
- 挑選方案問題(牛客競賽 思維題+推導公式)公式
- CF 19C 思維題STL應用
- C++奧賽一本通貪心題解C++
- 2017廣東工業大學程式設計競賽決賽 題解&原始碼(A,數學解方程,B,貪心博弈,C,遞迴,D,水,E,貪心,面試題,F,貪心,列舉,LCA,G,dp,記憶化搜尋,H,思維題)...程式設計原始碼遞迴面試題
- 更快學習 JS 的 6 個簡單思維技巧JS
- spring思維導圖,讓spring更加簡單易懂Spring
- Scrum:中日美思維橄欖:心,體驗,模型Scrum模型
- hdu5445 || 2015長春網路賽1009題 多重揹包問題
- 思維導圖的簡單畫法有人知道嗎?求分享
- C語言陣列實現約瑟夫環出圈問題 程式碼詳細註釋 簡單易懂C語言陣列
- 場上過不去的簡單題
- ZOJ Monthly, January 2019 - A Little Sub and Pascal's Triangle(找規律)
- c#簡單實現二維陣列和二維陣列列表List<>的轉置C#陣列
- 思維體系---技術思維、業務資料思維、產品思維、複合思維
- 力扣896. 單調數列-C語言實現-簡單題力扣C語言
- vue載入更多,上拉重新整理 VueScroller 簡單化思維Vue
- OI常見思維方式1(簡單/特殊情形——數學相關)
- 以增長黑客的思維來做廣告變現,能成功嗎?黑客
- 組合計數思維題
- 思維題專項訓練
- 求職思維和招聘思維求職
- 2013成都網路賽 兩個簡單題
- 2017第八屆天梯賽省賽C++C組【第一題:貪吃蛇長度】C++
- [無心插柳]簡單實現常用的表單校驗函式函式
- 【思維導圖-索引篇】搞定資料庫索引就是這麼簡單索引資料庫
- 【C/C++】ghost ddl指令碼簡單實現C++指令碼
- 簡單的素數問題(C++)C++
- 淺析工具思維、產品思維、品牌思維與定位
- 力扣566. 重塑矩陣-C語言實現-簡單題力扣矩陣C語言
- javascript實現二維陣列實現簡單介紹JavaScript陣列
- 2014北京網路賽1006||hdu5037 思維題
- LRU Cache 的簡單 C++ 實現C++
- 如何快速學習SGWin JavaScript:六個簡單的盤搭建思維技巧(上)JavaScript