2016-2017 ACM-ICPC Northeastern European Regional Contest (NEERC 16)

D:上下界费用流

将每个点和每个长度D的区间看作边,限制条件看作流量上下界,差分建图,无源汇最大费用费用流,非常巧妙的使用了差分建图。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#define N 100003
#define inf 2000000000
#define LL long long
using namespace std;
const LL INF=1e17;
int tot,nxt[N],point[N],v[N],remain[N],can[N],last[N],n,k,t1,t2,a[N],b[N];
LL cost[N],dis[N],ans;
void add(int x,int y,int z,LL k)
{
    tot++; nxt[tot]=point[x]; point[x]=tot; v[tot]=y; remain[tot]=z; cost[tot]=k;
    tot++; nxt[tot]=point[y]; point[y]=tot; v[tot]=x; remain[tot]=0; cost[tot]=-k;
}
int addflow(int s,int t)
{
    int ans=inf; int now=t;
    while (now!=s) {
        ans=min(ans,remain[last[now]]);
        now=v[last[now]^1];
    }
    now=t;
    while (now!=s) {
        remain[last[now]]-=ans;
        remain[last[now]^1]+=ans;
        now=v[last[now]^1];
    }
    return ans;
}
bool spfa(int s,int t)
{
    for (int i=1;i<=t;i++) dis[i]=INF,can[i]=0;;
    dis[s]=0; can[s]=1;
    queue<int> p; p.push(s);
    while (!p.empty()) {
        int now=p.front(); p.pop();
        can[now]=0;
        for (int i=point[now];i!=-1;i=nxt[i])
         if (remain[i]&&dis[v[i]]>dis[now]+cost[i]){
            dis[v[i]]=dis[now]+cost[i];
            last[v[i]]=i;
            if (!can[v[i]]) {
                can[v[i]]=1;
                p.push(v[i]);
             }
         }
    }
    if (dis[t]==INF) return false;
    int flow=addflow(s,t);
    ans+=dis[t];
    return true;
}
int main()
{
    freopen("delight.in","r",stdin);
    freopen("delight.out","w",stdout);
    scanf("%d%d%d%d",&n,&k,&t1,&t2);
    LL sum=0;
    tot=-1;
    memset(point,-1,sizeof(point));
    for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=(LL)a[i];
    for (int i=1;i<=n;i++) scanf("%d",&b[i]);
    int mn=t2; int mx=k-t1;
    int S=n+1;  int SS=S+1; int TT=SS+1;
    for (int i=1;i<=n;i++) add(i,i+k>n?TT:i+k,1,-(b[i]-a[i]));
    for (int i=1;i<=n;i++) add(i,i+1>n?TT:i+1,mx-mn,0);
    for (int i=1;i<=k;i++) add(S,i,inf,0);
    add(SS,S,mx,0);
    while (spfa(SS,TT));
    printf("%lld\n",sum-ans);
    for (int i=1;i<=2*n-1;i+=2)
     if (remain[i]) printf("E");
     else printf("S");
    printf("\n");
}

F:概率DP

设dp[i]表示从i这里切一次,i以及i之后w的期望,很容易看出这是可以DP转移的

若i处是w,dp[i]=1/n*∑(∑(sum_c[i..j])+dp[j])否则是:dp[i]=1/n*∑(∑(sum_w[i..j])+dp[j]),维护一下sum_c和sum_w即可

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <map>
using namespace std;
double sum[1000010],dp[1000010];
char str[1000010];
int n;

int main()
{
    freopen("foreign.in","r",stdin);
    freopen("foreign.out","w",stdout);
    int i;
    scanf("%s",str);
    n=strlen(str);
    for(i=0;i<n;i++)
    {
        if(str[i]==‘C‘) sum[i]=1.0;
    }
    for(i=n-1;i>=0;i--) sum[i]+=sum[i+1];
    double sum_c=0.0,sum_w=0.0,cnt=0.0;
    if(str[n-1]==‘C‘)sum_c=1.0;
    else sum_w=1.0;
    for(i=n-2;i>=0;i--)
    {

        if(str[i]==‘C‘)
        {
            dp[i]=(cnt+sum_w)/(double)(n-i);
            sum_c+=(double)(n-i);
        }
        else
        {
            dp[i]=(cnt+sum_c)/(double)(n-i);
            sum_w+=(double)(n-i);
        }
        //cout<<dp[i]<<endl;
        cnt+=dp[i];
    }
    printf("%.10lf\n",dp[0]);
    //cout<<dp[0]<<endl;
    return 0;
}

J:物理题

用求重心的公式强行算即可,n^2的复杂度根本不虚

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <map>
const double eps=1e-10;
using namespace std;

struct zx
{
    double x,y;
};

zx zx_all[5010],zx_a[5010];
int n,w,h,m;
int vis[5010][5010];
int num[5010];
double le[5010],ri[5010];

int main()
{
    freopen("jenga.in","ri",stdin);
    freopen("jenga.out","w",stdout);
    int i,j;
    scanf("%d%d%d%d",&n,&w,&h,&m);
    int l,k;
    num[h+1]=0;
    for(i=h;i>=1;i--)
    {
        le[i]=0;
        ri[i]=n*w;
        num[i]=num[i+1]+n;
        zx_all[i].x=zx_a[i].x=(double)(n*w)/2.0;
        zx_all[i].y=zx_a[i].y=(double)(n*w)/2.0;
    }
    int ans=-1;
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&l,&k);
        if(ans!=-1) continue;
        vis[l][k]=1;
        for(j=l;j>=1;j--)
        {
            num[j]--;
            if(num[j]==num[j+1]||num[h]==0)
            {
                ans=i;
                break;
            }
        }
        if(ans!=-1) continue;
        if(num[l]==num[l+1])
        {
            ans=i;
            break;
        }
        else
        {
            for(j=1;j<=n;j++)
            {
                if(!vis[l][j])
                {
                    le[l]=(double)(j-1)*w;
                    break;
                }
            }
            for(j=n;j>=1;j--)
            {
                if(!vis[l][j])
                {
                    ri[l]=(double)j*w;
                    break;
                }
            }
        }
        double temp=0;
        double tmp=0;
        for(j=1;j<=n;j++)
        {
            if(!vis[l][j])
            {
                temp+=((j-1)*w+w/2);
                tmp+=1.0;
            }
        }
        temp/=tmp;
        if(l%2==1)
        {
            zx_a[l].x=temp;
        }
        else
        {
            zx_a[l].y=temp;
        }
        for(j=l;j>=1;j--)
        {
            zx_all[j].x=(zx_all[j+1].x*num[j+1]+zx_a[j].x*(num[j]-num[j+1]))/num[j];
            zx_all[j].y=(zx_all[j+1].y*num[j+1]+zx_a[j].y*(num[j]-num[j+1]))/num[j];
            if(j!=h&&(j&1)&&((zx_all[j+1].x<=le[j]||zx_all[j+1].x>=ri[j])||(fabs(zx_all[j+1].x-le[j])<eps)||(fabs(zx_all[j+1].x-ri[j])<eps)))
            {
                ans=i;
                break;
            }
            else if(j!=h&&!(j&1)&&((zx_all[j+1].y<=le[j]||zx_all[j+1].y>=ri[j])||(fabs(zx_all[j+1].y-le[j])<eps)||(fabs(zx_all[j+1].y-ri[j])<eps)))
            {
                ans=i;
                break;
            }
        }
    }
    if(ans==-1)
    {
        puts("no");
    }
    else
    {
        puts("yes");
        printf("%d\n",ans);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/Hetui/p/9307919.html

时间: 2024-10-03 05:12:56

2016-2017 ACM-ICPC Northeastern European Regional Contest (NEERC 16)的相关文章

2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)

2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) A 题意:有 n 个时刻,第 i 个时刻要么会在 (xi,yi) 生成一个半径为 yi 的圆,要么射击 (xi,yi) 这个点,如果该点在某个圆内则把对应圆删除并输出该圆的标号,否则输出 -1 .任意时刻圆之间不会相交(可以相切). \(n \le 2*10^5, -10^9 \le x_i,y_i \le 10^9, y

2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15)C - Cactus Jubilee

题意:给一颗仙人掌,要求移动一条边,不能放在原处,移动之后还是一颗仙人掌的方案数(仙人掌:无向图,每条边只在一个环中),等价于先删除一条边,然后加一条边 题解:对于一颗仙人掌,分成两种边,1:环边:环上的边2,树边:非环上的边 考虑1.删除树边,那么只需联通两个联通快,那么方案数就是两个联通块乘积-1(除去删除的边) 2.删除环边,那么我们假设删除所有环,那么图变成了深林,方案数就是深林中每棵树任意两点连接,方案数就是全部的和,先维护一个每个环上的点有多少树边,对于每个树边联通块(大小x)共贡献

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Krak&#243;w

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik's RectangleProblem B: What does the fox say?Problem C: Magical GCDProblem D: SubwayProblem E: EscapeProblem F: DraughtsProblem G: History courseProblem H: C

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri

2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 1496    Accepted Submission(s): 723 Problem Description Kelukin is a businessman. Every day, he travels arou

2016年acm icpc 青岛站(中国石油大学(华东))总结

2016年acm icpc 青岛站(中国石油大学(华东))总结 2016年11月11日,在这个传说中所谓的单身节,我们出发了,做了整整一天的车来到了青岛.不得不提一下,作为一个身处华中沿海地区的童鞋,这是我人生第一次坐了这么久的高铁(真的无聊,无聊,无聊),然后到了青岛是晚上了(挤公交车真的是一件很刺激的事情). 海风那个吹, 海水那个涌, 冻得萌新瑟瑟发抖. 也许是知道我们要来挖石油的缘故吧, 老天爷特意给了我们三天晴天. 晚上也没啥事,就这么洗洗睡了,不对还有传说中学长带领学弟剁手呢! 第二

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 (Gym - 102082)

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 A - Digits Are Not Just Characters 签到. B - Arithmetic Progressions 题意:从给定的集合中选出最多的数构成等差数列. 题解:数字排序后,设\(dp[i][j]\)表示等差数列最后一个数字为\(a[i]\),倒数第二个数字为\(a[j]\)的最大个数.然后对于每一位枚举 \(i\),\(lower\_bound()\)找有无合法的

HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting

Brute Force Sorting Time Limit: 1 Sec  Memory Limit: 128 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=6215 Description Beerus needs to sort an array of N integers. Algorithms are not Beerus's strength. Destruction is what he excels. He can destr

2017 ACM/ICPC Asia Regional Shenyang Online

cable cable cable Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2084    Accepted Submission(s): 1348 Problem Description Connecting the display screen and signal sources which produce differen