HDU 4422 the Little Girl who picks mushrooms (2012 Chengdu Field Game c)

Source: Internet
Author: User

1. Title Description: Click to open the link

2. Problem-Solving ideas: The topic is a simple simulation, however, their own method is not the WA a lot of = =. Finally had to abandon their own ideas. Use 1 first to indicate a position that has not been used. You can enumerate 3 locations at a time, if you find that the 3 locations do not have 1 and their and cannot be divisible by 1024, then return 0, otherwise, find the other 2 locations that are not marked, if one of these 2 positions is-1, then directly return 1024, because we have already delivered three bags, If there is no certainty in the rest of the bag, then it will be 1024. Otherwise, calculate the number of the 2 positions and then see how much is left after subtracting several times 1024, which is the return value. Each time the enumeration's maximum value is updated with ans.

3. Code:

#include <iostream> #include <algorithm> #include <cassert> #include <string> #include < sstream> #include <set> #include <bitset> #include <vector> #include <stack> #include <map > #include <queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring > #include <cmath> #include <ctime> #include <cctype> #include <functional> #pragma comment ( linker, "/stack:1024000000,1024000000") using namespace std; #define ME (s) memset (s,0,sizeof (s)) #define REP (I,n) for ( int i=0;i< (n); i++) typedef long LONG ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair <int, I    nt> p;const int n=6;int v[6];int vis[5];int calc (int x,int y,int z) {int sum=v[x]+v[y]+v[z];    if ((sum%1024) &&v[x]!=-1&&v[y]!=-1&&v[z]!=-1) return 0;    int A, B;    Me (VIS);    Vis[x]=vis[y]=vis[z]=1;    for (int i=0;i<5;i++) if (!vis[i]) {a=i;vis[i]=1;break;} for (int i=a;i<5;i++) if (!vis[i]) {B=i;vis[i]=1;break;} if (v[a]==-1| | V[B]==-1) return 1024;    Hand over 3 bags still have the empty bag, then must be able to make up into the 1024x768 int res=v[a]+v[b];    while (res>1024) res-=1024; return res;}    int main () {int n;        while (~SCANF ("%d", &n)) {int ans=0;        memset (v,-1,sizeof (v));        for (int i=0;i<n;i++) scanf ("%d", &v[i]); for (int i=0;i<3;i++) for (int. j=i+1;j<4;j++) for (int k=j+1;k<5;k++) Ans=max (ans,c        ALC (i,j,k));    printf ("%d\n", ans); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4422 the Little Girl who picks mushrooms (2012 Chengdu Field Game c)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.