陈老师的多校联合20180808 map映射字符串
2014-08-09 20:47
288 查看
http://vjudge.net/contest/view.action?cid=51407#problem/A
Description
Your country has qualified for the FIFA 2010 South Africa World Cup. As the coach, you have made up the 23 men squad. Now you must select 11 of them as the starters. As is well known, there are four positions
in soccer: goalkeeper, defender, midfielder and striker. Your favorite formation is 4-4-2, that is, you should choose 4 defenders, 4 midfielders, 2 strikers, and of course, 1 goalkeeper. As a retired ACMer, you want to write a program to help you make decision.
Each person's ability has been evaluated as a positive integer. And what's more, for some special pairs of persons, if the two people are both on the field, there will be an additional effect (positive or negative). Now you should choose the 11 persons to
make the total value maximum.
Input
There are multiple test cases, separated by an empty line. The first 23 lines of each test case indicate each person's name Si, ability valueVi,
and position. The length of each name is no more than 30, and there are no whitespaces in the names. All the names are different. The ability values are positive integers and no more than 100. The position is one of ``goalkeeper", ``defender", ``midfielder"
and ``striker".
Then an integer M indicates that there are M special pairs. Each of the following M lines contains Si, Sj and Cij,
means that if Si and Sj are both on the field, the additional profit is Cij. (- 100
Cij
100). Si and Sj are
different strings, and must be in the previous 23 names. All the (Si, Sj) pairs are different.
Output
Output one line for each test case, indicating the maximum total ability values, that is, the total ability values of the 11 persons plus the additional effects. If you cannot choose a 4-4-2 formation, output
``impossible" instead.
Sample Input
Sample Output
题目大意:给你23个球员信息,挑出11个人组成一个4-4-2队形,并使得拼出的价值最高。
解题思路:map完成对字符串的映射,细节处理请看代码
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <map>
#include <string>
#define inf 0x3f3f3f3f
using namespace std;
map<string,int> mp,rank;
string str1,str2,str;
int value[30],add[30][30],G[30],S[30],M[30],D[30];
int n,m,a[13];
int main()
{
while(cin>>str1>>n>>str)
{
int _g=0,_m=0,_s=0,_d=0;
mp[str1]=0;
int cnt=0;
value[0]=n;
memset(G,0,sizeof(G));
memset(S,0,sizeof(S));
memset(M,0,sizeof(M));
memset(D,0,sizeof(D));
if(str=="goalkeeper")
G[_g++]=0;
else if(str=="striker")
S[_s++]=0;
else if(str=="midfielder")
M[_m++]=0;
else if(str=="defender")
D[_d++]=0;
for(int i=1; i<23; i++)
{
cin >> str1 >>n>>str;
mp[str1]=i;
value[i]=n;
if(str=="goalkeeper")
G[_g++]=i;
else if(str=="striker")
S[_s++]=i;
else if(str=="midfielder")
M[_m++]=i;
else if(str=="defender")
D[_d++]=i;
}
int m;
scanf("%d",&m);
memset(add,0,sizeof(add));
while(m--)
{
cin >> str1 >> str2 >> n;
add[mp[str1]][mp[str2]]=add[mp[str2]][mp[str1]]=n;
}
if(_g<1||_s<2||_m<4||_d<4)
{
printf("impossible\n");
continue;
}
int maxx=-inf;
for(int i=0; i<_g; i++)
for(int j=0; j<_s; j++)
for(int k=j+1; k<_s; k++)
for(int x=0; x<_m; x++)
for(int y=x+1; y<_m; y++)
for(int z=y+1; z<_m; z++)
for(int o=z+1; o<_m; o++)
for(int p=0; p<_d; p++)
for(int q=p+1; q<_d; q++)
for(int r=q+1; r<_d; r++)
for(int s=r+1; s<_d; s++)
{
int sum=0;
a[1]=G[i];
a[2]=S[j];
a[3]=S[k];
a[4]=M[x];
a[5]=M[y];
a[6]=M[z];
a[7]=M[o];
a[8]=D[p];
a[9]=D[q];
a[10]=D[r];
a[11]=D[s];
for(int ss=1; ss<=11; ss++)
sum+=value[a[ss]];
for(int ii=1; ii<=11; ii++)
for(int jj=ii+1; jj<=11; jj++)
if(add[a[ii]][a[jj]]!=0)
sum+=add[a[ii]][a[jj]];
maxx=max(sum,maxx);
}
printf("%d\n",maxx);
}
return 0;
}
Description
Your country has qualified for the FIFA 2010 South Africa World Cup. As the coach, you have made up the 23 men squad. Now you must select 11 of them as the starters. As is well known, there are four positions
in soccer: goalkeeper, defender, midfielder and striker. Your favorite formation is 4-4-2, that is, you should choose 4 defenders, 4 midfielders, 2 strikers, and of course, 1 goalkeeper. As a retired ACMer, you want to write a program to help you make decision.
Each person's ability has been evaluated as a positive integer. And what's more, for some special pairs of persons, if the two people are both on the field, there will be an additional effect (positive or negative). Now you should choose the 11 persons to
make the total value maximum.
Input
There are multiple test cases, separated by an empty line. The first 23 lines of each test case indicate each person's name Si, ability valueVi,
and position. The length of each name is no more than 30, and there are no whitespaces in the names. All the names are different. The ability values are positive integers and no more than 100. The position is one of ``goalkeeper", ``defender", ``midfielder"
and ``striker".
Then an integer M indicates that there are M special pairs. Each of the following M lines contains Si, Sj and Cij,
means that if Si and Sj are both on the field, the additional profit is Cij. (- 100
Cij
100). Si and Sj are
different strings, and must be in the previous 23 names. All the (Si, Sj) pairs are different.
Output
Output one line for each test case, indicating the maximum total ability values, that is, the total ability values of the 11 persons plus the additional effects. If you cannot choose a 4-4-2 formation, output
``impossible" instead.
Sample Input
Buffon 90 goalkeeper De_Sanctis 80 goalkeeper Marchetti 80 goalkeeper Zambrotta 90 defender Cannavaro 90 defender Chiellini 90 defender Maggio 90 defender Bonucci 80 defender Criscito 80 defender Bocchetti 80 defender Pirlo 90 midfielder Gattuso 90 midfielder De_Rossi 90 midfielder Montolivo 90 midfielder Camoranesi 80 midfielder Palombo 80 midfielder Marchisio 80 midfielder Pepe 80 midfielder Iaquinta 90 striker Di_Natale 90 striker Gilardino 80 striker Quagliarella 80 striker Pazzini 80 striker 1 Pirlo Quagliarella 50 ZhangSan01 50 goalkeeper ZhangSan02 50 defender ZhangSan03 50 defender ZhangSan04 50 defender ZhangSan05 50 defender ZhangSan06 50 defender ZhangSan07 50 defender ZhangSan08 50 defender ZhangSan09 50 defender ZhangSan10 50 defender ZhangSan11 50 defender ZhangSan12 50 defender ZhangSan13 50 defender ZhangSan14 50 defender ZhangSan15 50 defender ZhangSan16 50 midfielder ZhangSan17 50 midfielder ZhangSan18 50 midfielder ZhangSan19 50 midfielder ZhangSan20 50 midfielder ZhangSan21 50 midfielder ZhangSan22 50 midfielder ZhangSan23 50 midfielder 0
Sample Output
1030 impossible
题目大意:给你23个球员信息,挑出11个人组成一个4-4-2队形,并使得拼出的价值最高。
解题思路:map完成对字符串的映射,细节处理请看代码
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <map>
#include <string>
#define inf 0x3f3f3f3f
using namespace std;
map<string,int> mp,rank;
string str1,str2,str;
int value[30],add[30][30],G[30],S[30],M[30],D[30];
int n,m,a[13];
int main()
{
while(cin>>str1>>n>>str)
{
int _g=0,_m=0,_s=0,_d=0;
mp[str1]=0;
int cnt=0;
value[0]=n;
memset(G,0,sizeof(G));
memset(S,0,sizeof(S));
memset(M,0,sizeof(M));
memset(D,0,sizeof(D));
if(str=="goalkeeper")
G[_g++]=0;
else if(str=="striker")
S[_s++]=0;
else if(str=="midfielder")
M[_m++]=0;
else if(str=="defender")
D[_d++]=0;
for(int i=1; i<23; i++)
{
cin >> str1 >>n>>str;
mp[str1]=i;
value[i]=n;
if(str=="goalkeeper")
G[_g++]=i;
else if(str=="striker")
S[_s++]=i;
else if(str=="midfielder")
M[_m++]=i;
else if(str=="defender")
D[_d++]=i;
}
int m;
scanf("%d",&m);
memset(add,0,sizeof(add));
while(m--)
{
cin >> str1 >> str2 >> n;
add[mp[str1]][mp[str2]]=add[mp[str2]][mp[str1]]=n;
}
if(_g<1||_s<2||_m<4||_d<4)
{
printf("impossible\n");
continue;
}
int maxx=-inf;
for(int i=0; i<_g; i++)
for(int j=0; j<_s; j++)
for(int k=j+1; k<_s; k++)
for(int x=0; x<_m; x++)
for(int y=x+1; y<_m; y++)
for(int z=y+1; z<_m; z++)
for(int o=z+1; o<_m; o++)
for(int p=0; p<_d; p++)
for(int q=p+1; q<_d; q++)
for(int r=q+1; r<_d; r++)
for(int s=r+1; s<_d; s++)
{
int sum=0;
a[1]=G[i];
a[2]=S[j];
a[3]=S[k];
a[4]=M[x];
a[5]=M[y];
a[6]=M[z];
a[7]=M[o];
a[8]=D[p];
a[9]=D[q];
a[10]=D[r];
a[11]=D[s];
for(int ss=1; ss<=11; ss++)
sum+=value[a[ss]];
for(int ii=1; ii<=11; ii++)
for(int jj=ii+1; jj<=11; jj++)
if(add[a[ii]][a[jj]]!=0)
sum+=add[a[ii]][a[jj]];
maxx=max(sum,maxx);
}
printf("%d\n",maxx);
}
return 0;
}
相关文章推荐
- 陈老师的多校联合 D题 字符串处理起来挺麻烦
- 陈老师的多校联合 20140809 C题
- 陈老师的多校联合20140811||HDU 3236 ||2009年武汉站G题 01背包问题
- COJ: Languages(字符串处理、map映射)
- HDU1075-字符串映射-字典树&map
- hdu 4034 预处理+map映射字符串
- map映射 【字符串&整型】
- 陈老师的多校联合 20140808 E题
- 陈老师的多校联合20140816||spoj10237 bfs
- 陈老师的多校联合20140815 ||uvalive 5881 区间处理
- 多校联合集训 A. 字符串“水”题 (状压+哈希)
- UVALive 5691 二分图匹配||陈老师的多校联合20140818 J题
- 陈老师的多校联合 20140809
- 陈老师的多校联合20140816||SPOJ AMR11B 三角形的有向面积
- 2015多校联合第十场 hdu5414CRB and String字符串思维题
- HDU 2017 多校联合训练赛2 1011 6055 Regular polygon map&pair
- 陈老师的多校联合2009年武汉站D题 ||hdu 3033
- 陈老师的多校联合20140818||Uvalive 5683 模拟
- 陈老师的多校联合 I题 二分
- 陈老师的多校联合2010811c题||09年武汉站||hdu3232