这题真的是有点毒,没说数据范围,我怕数太大分两次去二分,但是二元关系分两次二分还是错了。
然后看了qls代码发现,数据范围其实很小。。那直接枚举check就ok了啊
这一场题的顺序全是乱的,第一次打这样的cf,心累。。
代码:
#include <bits/stdc++.h>
using namespace std;
struct node
{
int point;
string nam;
int id;
int x;
int y;
bool operator < (const node & a)const{
if(a.point==point)
{
if(a.x-a.y==x-y)
{
if(x!=a.x)return x>a.x;
else return nam<a.nam;
}
else return x-y>a.x-a.y;
}
else return point>a.point;
}
}t[5], tmp[5];
map<string, int>mp;
int book[6];
int f(int x, int y, int o, int e)
{
int i;
for(i=1; i<=4; i++)
{
tmp[i]=t[i];
}
tmp[o].point+=3;
tmp[o].x+=x, tmp[e].y+=x;
tmp[o].y+=y, tmp[e].x+=y;
sort(tmp+1, tmp+5);
if(tmp[1].id==o || tmp[2].id==o)return true;
return false;
}
int main()
{
string a, b;
int x, y, t1, t2;
int cnt=0;
for(int i=1; i<=5; i++)
{
cin>>a>>b;
scanf("%d:%d", &x, &y);
if(!mp[a])
{
t1=mp[a]=++cnt;
}
else t1=mp[a];
if(!mp[b])
{
t2=mp[b]=++cnt;
}
else t2=mp[b];
t[t1].nam=a, t[t2].nam=b;
t[t1].id=t1, t[t2].id=t2;
t[t1].x+=x, t[t1].y+=y;
t[t2].x+=y, t[t2].y+=x;
if(x>y)t[t1].point+=3;
else if(x==y)t[t1].point++, t[t2].point++;
else t[t2].point+=3;
if(a=="BERLAND" || b=="BERLAND")book[t1]=book[t2]=1;
}
/*
for(int i=1; i<=4; i++)
{
printf("%d %d %d %d\n", t[i].id, t[i].point, t[i].x, t[i].y);
}
*/
int e, o;
for(int i=1; i<=4; i++)if(!book[i])e=i;
for(int i=1; i<=4; i++)if(i==mp["BERLAND"])o=i;
int l=0, r=0;
for(int i=0; i<=100; i++)
{
for(int j=0; j<i; j++)
{
if(f(i, j, o, e) && ((l==r && l==0) ||( (i-j)<(l-r) ||(i-j==(l-r) && j<r))))
{
l=i, r=j;
}
}
}
if(l!=0)printf("%d:%d\n", l, r);
else printf("IMPOSSIBLE\n");
}