# 洛谷4951 地震 bzoj1816扑克牌 洛谷3199最小圈 / 01分数规划

 1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #define go(i,a,b) for(register int i=a;i<=b;i++)
5 #define ll long long
6 #define db long double
7 #define M 10001
8 #define N 401
9 #define inf 1e15
10 #define eps 1e-12
11 using namespace std;
13 {
14     ll x=0,y=1;char c=getchar();
15     while(c<'0'||c>'9') {if(c=='-') y=-1;c=getchar();}
16     while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
17     return x*y;
18 }
19 struct node{int u,v;ll t,c;db w;}a[M];
20 ll n,m,f,fa[N];
21 int find(int x){if(x==fa[x])return x;return fa[x]=find(fa[x]);}
22 bool cmp(node x,node y){return x.w<y.w;}
23 bool ck(db x)
24 {
25     go(i,1,m) a[i].w=a[i].c+a[i].t*x/1e7;
26     db ans=f+eps;//这里加eps是为了保证精度
27     //-----------------------------
28     sort(a+1,a+m+1,cmp);
29     go(i,1,n) fa[i]=i;
30     go(i,1,m)
31     {
32         int uf=find(a[i].u),vf=find(a[i].v);
33         if(uf==vf) continue;
34         fa[uf]=vf;
35         ans-=a[i].w;
36         if(ans<0)return 0;
37     }//---------------------------最小生成树
38     return 1;
39 }
40 int main()
41 {
42     freopen("quake.in","r",stdin);
43     freopen("quake.out","w",stdout);
45     db l=1,r=inf;
47     if(!ck(0)) {printf("0.0000");return 0;}
48     while(l<r)
49     {
50         db mid=(l+r)/2;
51         if(ck(mid+1)) l=mid+1;
52         else r=mid;
53     }
54     printf("%.4Lf",l/(db)1e7);
55     return 0;
56 }
View Code

bzoj1816扑克牌

 1 #include<iostream>
2 #include<cstdio>
3 #define go(i,a,b) for(register int i=a;i<=b;i++)
4 #define ll long long
5 #define M 1000001
6 #define inf 1e12
7 using namespace std;
9 {
10     ll x=0,y=1;char c=getchar();
11     while(c<'0'||c>'9') {if(c=='-') y=-1;c=getchar();}
12     while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
13     return x*y;
14 }
15 int n,m;
16 ll ct,c[M],l,r=inf;
17 bool ck(ll x)
18 {
19     ll nm=min(x,(ll)m);
20     go(i,1,n){if(c[i]<x)nm=nm-(x-c[i]);if(nm<0)return 0;}
21     return 1;
22 }
23 int main()
24 {
25     freopen("cards.in","r",stdin);
26     freopen("cards.out","w",stdout);
29     while(l<r)
30     {
31         ll mid=(l+r)>>1;
32         if(ck(mid+1)) l=mid+1;
33         else r=mid;
34     }
35     printf("%lld",l);
36     return 0;
37 }
View Code

洛谷3199最小圈

 1 #include<iostream>
2 #include<cstdio>
3 #define R register
4 #define go(i,a,b) for(R int i=a;i<=b;i++)
5 #define db long double
6 #define M 10001
7 #define N 3001
8 #define inf 1e10
9 #define eps 1e-10
10 using namespace std;
11 int rd()
12 {
13     int x=0,y=1;char c=getchar();
14     while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
15     while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
16     return x*y;
17 }
18 int n,m,b[N],cnt;
19 bool in[N],flag;
20 db dis[N];
21 struct node{int v,nt;db w;}a[M];
22 void add(int u,int v,db w){a[++cnt].nt=b[u];a[cnt].v=v;a[cnt].w=w;b[u]=cnt;}
23 void ck(int u,db x)
24 {
25     in[u]=1;
26     for(R int i=b[u];i;i=a[i].nt)
27     {
28         int v=a[i].v;db w=a[i].w;
29         if(dis[u]+w-x<dis[v])
30         {
31             if(in[v]||flag){flag=1;return;}
32             dis[v]=dis[u]+w-x;
33             ck(v,x);
34         }
35     }
36     in[u]=0;
37 }
38 int main()
39 {
40     n=rd();m=rd();
42     db l=-inf,r=inf;
43     while(r-l>eps)
44     {
45         db mid=(l+r)/2;flag=0;
46         go(i,1,n){in[i]=0;dis[i]=0;}
47         go(i,1,n){ck(i,mid);if(flag)break;}
48         if(flag) r=mid;
49         else l=mid;
50     }
51     printf("%.8Lf",l);
52     return 0;
53 }
View Code

posted @ 2019-02-12 21:21  DTTTTTTT  阅读(132)  评论(0编辑  收藏  举报