HDU - 4422-The Little Girl who Picks Mushrooms

题目链接:https://vjudge.net/problem/HDU-4422

题目大意:

自行百度

题目分析:

当n<=3的时候,易得可以得到的最多的蘑菇是1024。

当n>3时,可以进行分类讨论。

注意有两个莫名奇妙的毒点:

1.我用取模WA而用while不断相减AC

2.三个相加等于零的情况也可以通过

给出代码:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <string>
 4 #include <set>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <cstring>
 8 #include <vector>
 9 using namespace std;
10 int num[10];
11 int main()
12 {
13     int n;
14     while(cin>>n)
15     {
16         int sum=0;
17         for(int i=0;i<n;i++)
18         {
19             scanf("%d",&num[i]);
20             sum+=num[i];
21         }
22         if(n<=3)
23             cout<<1024<<endl;
24         else
25         {
26             if(n==4)
27             {
28                 int flag=1;
29                 for(int i=0;i<n;i++)
30                 {
31                     int t=sum-num[i];
32                     if(t%1024==0)
33                     {
34                         cout<<1024<<endl;
35                         flag=0;
36                         break;
37                     }
38                 }
39                 if(flag)
40                 {
41                     int maxn=0;
42                     for(int i=0;i<n;i++)
43                     {
44                         for(int j=i+1;j<n;j++)
45                         {
46                             int t=num[i]+num[j];
47                             while(t>1024)
48                                 t-=1024;
49                             maxn=max(maxn,t);
50                         }
51                     }
52                     cout<<maxn<<endl;
53                 }
54             }
55             if(n==5)
56             {
57                 int maxn=0;
58                 for(int i=0;i<n;i++)
59                 {
60                     for(int j=i+1;j<n;j++)
61                     {
62                         for(int k=j+1;k<n;k++)
63                         {
64                             int t=num[i]+num[j]+num[k];
65                             if(t%1024==0)
66                             {
67                                 int tt=sum-t;
68                                 while(tt>1024)
69                                         tt-=1024;
70                                 maxn=max(tt,maxn);
71                             }
72                         }
73                     }
74                 }
75                 cout<<maxn<<endl;
76             }
77         }
78     }
79     return 0;
80 }

时间: 2024-08-01 01:41:44

HDU - 4422-The Little Girl who Picks Mushrooms的相关文章

HDU 4422 The Little Girl who Picks Mushrooms(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4422 Problem Description 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 mus

HDU 4422 The Little Girl who Picks Mushrooms (2012年成都赛区现场赛C题)

1.题目描述:点击打开链接 2.解题思路:本题是一道简单模拟题,然而,自己的方法不对WA了很多次==.最后不得不弃用自己的思路了.首先用-1表示还没有使用过的位置.可以每次枚举3个位置,如果发现这3个位置中没有-1且他们的和不能被1024整除,那么return 0,否则,找到没有被标记的另外2个位置,如果这2个位置其中一个为-1,那么直接返回1024,因为我们已经交了三个袋子了,剩下的袋子中如果又没有确定的,那么一定可以凑成1024.否则,计算这2个位置的和,然后看减去若干次1024后剩下多少,

ZOJ 3657 The Little Girl who Picks Mushrooms

The Little Girl who Picks Mushrooms Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 365764-bit integer IO format: %lld      Java class name: Main It's yet another festival season in Gensokyo. Little girl Alic

状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)

题目传送门 题意:采蘑菇.现在采了n座山,共5座山,最后要求有三个篮子的蘑菇量是1024的整数倍,丢掉后一直减1024直到不超过1024 分析:n <= 3时直接1024,否则状压枚举哪三个篮子丢弃,更新最值 /************************************************ * Author :Running_Time * Created Time :2015/10/28 星期三 19:21:49 * File Name :C.cpp *************

2012长春赛区题解(部分)

总结起来自己还是太逗比,DP还是太弱,而DP却恰是算法思维能力的体现,现在要开始注重加强这方面的训练,遇到这类题目总是不敢想,令人担忧. Problem B ZOJ 3656 Bit Magic http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3656 分析: 总共N个数,每个b[i][j]会对a[i]和a[j]的对应二进制位产生一定影响,具体见题目,我们需要做的是判断每个数的每个位是0或1,根据关系建立边,然后直接2sa

STL 全排列

The Little Girl who Picks Mushrooms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1805    Accepted Submission(s): 579 Problem Description It's yet another festival season in Gensokyo. Little

hdu 6406 Taotao Picks Apples (2018 Multi-University Training Contest 8 1010)(二分,前缀和)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=6406 思路: 暴力,预处理三个前缀和:[1,n]桃子会被摘掉,1到当前点的最大值,1到当前点被摘掉的桃子的数量,然后我们枚举修改p点造成的所有影响,: 1,假如新输入的点比原先的点的值更大,那么我们对修改后p这个点的值和[1,p-1]的最大值关系进行分析,也就是分析前半段的影响:(1)如果p点大于1-p-1的最大值的时候我们直接利用前缀和O(1)得到[1,p-1]有多少个桃子被摘掉,然后加上当前这个.(

hdu 6406 Taotao Picks Apples 线段树 单点更新

Taotao Picks Apples Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2506    Accepted Submission(s): 786 Problem Description There is an apple tree in front of Taotao's house. When autumn comes

【hdu 6406】Taotao Picks Apples

[链接] 我是链接,点我呀:) [题意] 题意相当于问你改变一个位置之后. 从左往右扫描最大值.这个最大值会改变多少次. [题解] 假设我们改变的是i这个位置,下面说的a[i]都是改成q之后的a[i] 我们完全可以直接暴力算出来左边的最大值会改变多少次以及右边的最大值会改变多少次. 那么如何找呢? 首先在1..i-1当中找到那个最大值a[idx1] 这个可以用st表预处理出来. 然后如果a[i]这个位置是更新最大值中的某一次的话ans++. 显然a[i]要满足>a[idx1] 如果不满足的话,那