zoukankan      html  css  js  c++  java
  • ZOJ3229 Shoot the Bullet [未AC]

    Time Limit: 2 Seconds      Memory Limit: 32768 KB      Special Judge

    Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It is a utopia where humans and other beings such as fairies, youkai(phantoms), and gods live peacefully together. Shameimaru Aya is a crow tengu with the ability to manipulate wind who has been in Gensokyo for over 1000 years. She runs the Bunbunmaru News - a newspaper chock-full of rumors, and owns the Bunkachou - her record of interesting observations for Bunbunmaru News articles and pictures of beautiful danmaku(barrange) or cute girls living in Gensokyo. She is the biggest connoisseur of rumors about the girls of Gensokyo among the tengu. Her intelligence gathering abilities are the best in Gensokyo!

    During the coming n days, Aya is planning to take many photos of m cute girls living in Gensokyo to write Bunbunmaru News daily and record at least Gx photos of girl x in total in the Bunkachou. At the k-th day, there are Ck targets, Tk1, Tk2, ..., TkCk. The number of photos of target Tki that Aya takes should be in range [Lki, Rki], if less, Aya cannot write an interesting article, if more, the girl will become angry and use her last spell card to attack Aya. What's more, Aya cannot take more than Dk photos at the k-th day. Under these constraints, the more photos, the better.

    Aya is not good at solving this complex problem. So she comes to you, an earthling, for help.

    Input

    There are about 40 cases. Process to the end of file.

    Each case begins with two integers 1 <= n <= 365, 1 <= m <= 1000. Then m integers, G1, G2, ..., Gm in range [0, 10000]. Then n days. Each day begins with two integer 1 <= C <= 100, 0 <= D <= 30000. Then C different targets. Each target is described by three integers, 0 <= T < m, 0 <= L <= R <= 100.

    Output

    For each case, first output the number of photos Aya can take, -1 if it's impossible to satisfy her needing. If there is a best strategy, output the number of photos of each girl Aya should take at each day on separate lines. The output must be in the same order as the input. If there are more than one best strategy, any one will be OK.

    Output a blank line after each case.

    Sample Input

    2 3
    12 12 12
    3 18
    0 3 9
    1 3 9
    2 3 9
    3 18
    0 3 9
    1 3 9
    2 3 9
    
    2 3
    12 12 12
    3 18
    0 3 9
    1 3 9
    2 3 9
    3 18
    0 0 3
    1 3 6
    2 6 9
    
    2 3
    12 12 12
    3 15
    0 3 9
    1 3 9
    2 3 9
    3 21
    0 0 3
    1 3 6
    2 6 12
    
    

    Sample Output

    36
    6
    6
    6
    6
    6
    6
    
    36
    9
    6
    3
    3
    6
    9
    
    -1
    
    

    图论 网络流

    复习了一波有上下界网络流的姿势。

    顺便复习了一下东方的设定

    题面里的罗马音居然都能看懂,是该说新标日姿势没忘光呢还是四斋蒸鹅心呢

    如何求带上下界的最大流?

    在求出可行流以后,删掉超级源汇,从旧源到旧汇跑网络流,把能用的残余流量都流掉,再加上原先的下界即可。

    好像这道题的SPJ挂掉了,近几个月的提交结果全是Judge Internal Error

    代码不保证正确,仅供参考

      1 /*by SilverN*/
      2 #include<iostream>
      3 #include<algorithm>
      4 #include<cstdio>
      5 #include<cmath>
      6 #include<cstring>
      7 #include<queue>
      8 using namespace std;
      9 const int INF=0x3f3f3f3f;
     10 const int mxn=100010;
     11 int read(){
     12     int x=0,f=1;char ch=getchar();
     13     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
     14     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
     15     return x*f;
     16 }
     17 struct edge{
     18     int v,nxt,f;
     19 }e[mxn<<1];
     20 int hd[mxn],mct=1;
     21 inline void add_edge(int u,int v,int f){
     22     e[++mct].v=v;e[mct].nxt=hd[u];e[mct].f=f;hd[u]=mct;return;
     23 }
     24 inline void insert(int u,int v,int f){
     25 //    printf("ins:%d %d %d
    ",u,v,f);
     26     add_edge(u,v,f);add_edge(v,u,0);
     27 }
     28 int ST,ED,S,T;
     29 int n,m;
     30 queue<int>q;
     31 int d[mxn];
     32 bool BFS(){
     33     for(int i=0;i<=ED;i++)d[i]=0;
     34     q.push(ST);
     35     d[ST]=1;
     36     while(!q.empty()){
     37         int u=q.front();q.pop();
     38         for(int i=hd[u];i;i=e[i].nxt){
     39             int v=e[i].v;
     40             if(e[i].f && !d[v]){
     41                 d[v]=d[u]+1;
     42                 q.push(v);
     43             }
     44         }
     45     }
     46     return d[ED];
     47 }
     48 int cur[mxn];
     49 int DFS(int u,int lim){
     50     if(u==ED)return lim;
     51     int f=0,tmp;
     52     for(int &i=cur[u];i;i=e[i].nxt){
     53         int v=e[i].v;
     54         if(e[i].f && d[v]==d[u]+1 && (tmp=DFS(v,min(lim,e[i].f)))){
     55             e[i].f-=tmp;
     56             e[i^1].f+=tmp;
     57             lim-=tmp;
     58             f+=tmp;
     59             if(!lim)return f;
     60         } 
     61     }
     62     d[u]=0;
     63     return f;
     64 }
     65 int Dinic(){
     66     int res=0,flow=0;
     67     while(BFS()){
     68         for(int i=0;i<=ED;i++)cur[i]=hd[i];
     69         while(flow=DFS(ST,INF))res+=flow;
     70     }
     71     return res;
     72 }
     73 //
     74 int du[mxn];
     75 int D[mxn];
     76 int down[450][2333];
     77 bool vis[450][2333];
     78 int id[450][2333];
     79 void solve_MX(){
     80     int i,j;
     81     ST=S;ED=T;
     82     int ans=Dinic();
     83     for(i=1;i<=n;i++){
     84         for(j=hd[i];j;j=e[j].nxt){
     85             int v=e[j].v;
     86             if(v>n && v<T){
     87                 down[i][v-n]+=e[j^1].f;
     88             }
     89         }
     90     }
     91     printf("%d
    ",ans);
     92     for(i=1;i<=n;i++){
     93         for(j=1;j<=m;j++){
     94             if(vis[i][j])
     95                 printf("%d
    ",down[i][j]);
     96         }
     97     }
     98     return;
     99 }
    100 void init(){
    101     memset(hd,0,sizeof hd);mct=1;
    102     memset(vis,0,sizeof vis);
    103     memset(du,0,sizeof du);
    104     return;
    105 }
    106 int main(){
    107     freopen("in.txt","r",stdin);
    108     int i,j;
    109     while(scanf("%d%d",&n,&m)!=EOF){
    110         init();
    111         S=0;T=n+m+1;ST=T+1;ED=ST+1;
    112         int u,v,w,L,R;
    113         for(i=1;i<=m;i++){
    114             w=read();
    115             du[i+n]-=w;
    116             du[T]+=w;
    117             insert(i+n,T,INF-w);
    118         }
    119         for(i=1;i<=n;i++){
    120             int C=read();D[i]=read();
    121             insert(S,i,D[i]);
    122             for(j=1;j<=C;j++){
    123                 v=read()+1;L=read();R=read();
    124                 du[i]-=L;
    125                 du[v+n]+=L;
    126                 down[i][v]=L;
    127                 vis[i][v]=1;
    128                 insert(i,v+n,R-L);
    129                 id[i][v]=mct;
    130             }
    131         }
    132         insert(T,S,INF);
    133         int smm=0;
    134         for(i=S;i<=T;i++){
    135             if(du[i]>0)smm+=du[i],insert(ST,i,du[i]);
    136                 else insert(i,ED,-du[i]);
    137         }
    138         int res=Dinic();//printf("res:%d smm:%d
    ",res,smm);
    139         if(res!=smm){
    140             puts("-1");continue;
    141         }
    142         else{
    143             solve_MX();
    144         }
    145     }
    146     return 0;
    147 }
  • 相关阅读:
    前后端分离基于Oauth2的SSO单点登录怎样做?
    Spring Security基于Oauth2的SSO单点登录怎样做?一个注解搞定
    微服务业务监控和行为分析怎么做?试试日志埋点
    Spring Cloud Gateway的动态路由怎样做?集成Nacos实现很简单
    Spring Cloud异步场景分布式事务怎样做?试试RocketMQ
    Apache RocketMQ 消息队列部署与可视化界面安装
    Spring Cloud同步场景分布式事务怎样做?试试Seata
    实施微服务架构的关键技术
    Spring Cloud开发人员如何解决服务冲突和实例乱窜?(IP实现方案)
    独立博客,从零到千万访问,这三年我都做了什么
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6973612.html
Copyright © 2011-2022 走看看