2014
11-27

# Greedy Tino

Tino wrote a long long story. BUT! in Chinese…
So I have to tell you the problem directly and discard his long long story. That is tino want to carry some oranges with "Carrying pole", and he must make two side of the Carrying pole are the same weight. Each orange have its’ weight. So greedy tino want to know the maximum weight he can carry.

The first line of input contains a number t, which means there are t cases of the test data.
for each test case, the first line contain a number n, indicate the number of oranges.
the second line contains n numbers, Wi, indicate the weight of each orange
n is between 1 and 100, inclusive. Wi is between 0 and 2000, inclusive. the sum of Wi is equal or less than 2000.

The first line of input contains a number t, which means there are t cases of the test data.
for each test case, the first line contain a number n, indicate the number of oranges.
the second line contains n numbers, Wi, indicate the weight of each orange
n is between 1 and 100, inclusive. Wi is between 0 and 2000, inclusive. the sum of Wi is equal or less than 2000.

1
5
1 2 3 4 5

Case 1: 7

# HDU3578 Greedy Tino

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 862    Accepted Submission(s): 295

Problem Description
Tino wrote a long long story. BUT! in Chinese…
So I have to tell you the problem directly and discard his long long story. That is tino want to carry some oranges with “Carrying pole”, and he must make two side of the Carrying pole are the same weight. Each orange have its’ weight. So greedy tino want to know the maximum weight he can carry.

Input
The first line of input contains a number t, which means there are t cases of the test data.
for each test case, the first line contain a number n, indicate the number of oranges.
the second line contains n numbers, Wi, indicate the weight of each orange
n is between 1 and 100, inclusive. Wi is between 0 and 2000, inclusive. the sum of Wi is equal or less than 2000.

Output
For each test case, output the maximum weight in one side of Carrying pole. If you can’t carry any orange, output -1. Output format is shown in Sample Output.

Sample Input
1
5
1 2 3 4 5

Sample Output
Case 1: 7

Author
Tino
******************************************************

#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
#include <string>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define N 4005
#define M
#define E
#define INF 0x3f3f3f3f
#define eps 1e-8
#define LL long long
#define D(a) ((a)*(a))
using namespace std;

int dp[N],n,a[N],b[N];

void re(void)
{
scanf("%d",&n);
}

void run(void)
{
memset(dp,-1,sizeof(dp));
dp[2000]=0;
int flag=0;
for(int i=0;i<n;i++)
{
int v;
scanf("%d",&v);
if(v==0)flag++;
memset(a,-1,sizeof(a));
memset(b,-1,sizeof(b));
for(int i=0;i<=4000;i++)
if(~dp[i])
a[i-v]=max(dp[i-v],dp[i]+v),
b[i+v]=max(dp[i+v],dp[i]+v);
for(int i=0;i<=4000;i++)
dp[i]=max(dp[i],max(a[i],b[i]));
}
if(dp[2000]==0&&flag<1)printf("-1\n");
else printf("%d\n",dp[2000]/2);
}

int main()
{
int ncase;
scanf("%d",&ncase);
for(int i=1;i<=ncase;i++)
{
re();
printf("Case %d: ",i);
run();
}
return 0;
}


2. 可以根据二叉排序树的定义进行严格的排序树创建和后序遍历操作。如果形成的排序树相同，其树的前、中、后序遍历是相同的，但在此处不能使用中序遍历，因为，中序遍历的结果就是排序的结果。经在九度测试，运行时间90ms，比楼主的要快。

3. #include <cstdio>
#include <cstring>

const int MAXSIZE=256;
//char store[MAXSIZE];
char str1[MAXSIZE];
/*
void init(char *store) {
int i;
store['A']=’V', store['B']=’W',store['C']=’X',store['D']=’Y',store['E']=’Z';
for(i=’F';i<=’Z';++i) store =i-5;
}
*/
int main() {
//freopen("input.txt","r",stdin);
//init(store);
char *p;
while(fgets(str1,MAXSIZE,stdin) && strcmp(str1,"STARTn")==0) {
if(p=fgets(str1,MAXSIZE,stdin)) {
for(;*p;++p) {
//*p=store[*p]
if(*p<’A’ || *p>’Z') continue;
if(*p>’E') *p=*p-5;
else *p=*p+21;
}
printf("%s",str1);
}
fgets(str1,MAXSIZE,stdin);
}
return 0;
}

4. I like your publish. It is great to see you verbalize from the coronary heart and clarity on this essential subject matter can be easily noticed.