您的位置:首页 > 其它

2395: [Balkan 2011]Timeismoney

2018-03-27 20:01 246 查看
推荐一篇炒鸡强的blog

好就这样…不想写其他的,看这个就ojbk了

c++代码如下:

#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x; i <= y; ++ i)
#define repd(i,x,y) for(register int i = x; i >= y; -- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
x = 0;char c;int sign = 1;
do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
x *= sign;
}

const int N = 1e4 + 50;
struct Edge { int u,v,c,t,w; }edge
;
struct Point { int x,y; }A,B,ans;
bool operator < (const Edge a,const Edge b) { return a.w < b.w; }
int n,m,f
;

int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }

inline void solve(Point&a)
{
a.x = a.y = 0;
rep(i,1,n) f[i] = i;
sort(edge + 1,edge + 1 + m);
rep(i,1,m)
{
int x = find(edge[i].u),y = find(edge[i].v);
if(x != y)
{
f[x] = y;
a.x += edge[i].c;
a.y += edge[i].t;
}
}
if(1ll * a.x * a.y < 1ll * ans.x * ans.y || (a.x * a.y == ans.x * ans.y &&  a.x < ans.x))
ans = a;
}

ll cross(Point A,Point B) { return A.x * B.y - B.x * A.y; }

void work(Point A,Point B)
{
Point C;
rep(i,1,m) edge[i].w = edge[i].c* (A.y - B.y) + edge[i].t *(B.x-A.x);
solve(C);
if(cross((Point){C.x - A.x,C.y - A.y},(Point){B.x - A.x,B.y - A.y}) <= 0)
return;
work(A,C);
work(C,B);
}

int main()
{
ans.x = 1e9+7; ans.y = 1e9+7;
read(n); read(m);
rep(i,1,m)
read(edge[i].u), read(edge[i].v),
read(edge[i].c),read(edge[i].t),
++edge[i].u,++edge[i].v;

rep(i,1,m) edge[i].w = edge[i].c;
solve(A);
rep(i,1,m) edge[i].w = edge[i].t;
solve(B);

work(A,B);
cout << ans.x << ' ' << ans.y;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: