zoukankan      html  css  js  c++  java
  • 【CF1020E】Sergey's problem(构造)

    题意:

    思路:这是一道论文题 https://link.springer.com/content/pdf/10.1007/BFb0066192.pdf

    From http://www.cnblogs.com/zhouzhendong/p/CF1019C.html

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 #include<bitset>
    12 using namespace std;
    13 typedef long long ll;
    14 typedef unsigned int uint;
    15 typedef unsigned long long ull;
    16 typedef pair<int,int> PII;
    17 typedef vector<int> VI;
    18 #define fi first
    19 #define se second 
    20 #define MP make_pair
    21 #define N      1100000
    22 #define M      51
    23 #define MOD 1000000007
    24 #define eps 1e-8 
    25 #define pi     acos(-1)
    26 #define oo     3e14
    27 
    28 vector<int> c[N];
    29 int a[N],b[N],q[N];
    30  
    31 int main()
    32 { 
    33     int n,m;
    34     scanf("%d%d",&n,&m);
    35     for(int i=1;i<=n;i++) c[i].clear();
    36     for(int i=1;i<=m;i++)
    37     {
    38         int x,y;
    39         scanf("%d%d",&x,&y);
    40         c[x].push_back(y);
    41     }
    42     for(int i=1;i<=n;i++)
    43      if(!a[i])
    44      {
    45          for(int j=0;j<=(int)c[i].size()-1;j++) a[c[i][j]]=1;
    46          a[i]=b[i]=1;
    47      }
    48     for(int i=n;i>=1;i--)
    49      if(b[i])
    50      {
    51          for(int j=0;j<=(int)c[i].size()-1;j++) b[c[i][j]]=0;
    52      }
    53     int ans=0;
    54     for(int i=1;i<=n;i++) 
    55      if(b[i]) q[++ans]=i;
    56     printf("%d
    ",ans);
    57     for(int i=1;i<=ans-1;i++) printf("%d ",q[i]);
    58     printf("%d
    ",q[ans]);
    59     return 0;
    60 }
  • 相关阅读:
    Execution Contexts (执行上下文)
    OOP—ECMAScript实现详解
    requireJS入门
    SqlServer 傲娇的表变量
    CSharp进阶 引用类型引发的血案
    CSharp进阶 都是请求惹的祸
    z-index问题
    js中事件(自定义事件)
    做了个后末日朋克风的梦
    昨晚的梦
  • 原文地址:https://www.cnblogs.com/myx12345/p/10073117.html
Copyright © 2011-2022 走看看