ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心)

分析:贪心地删边后检查每个点的度即可,这也是正确的做法?

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4+5;
struct Edge{
    int u,v,next;
}edges[MAXN<<2];
int head[MAXN],tot;
int deg[MAXN];

void init()
{
    memset(head,-1,sizeof(head));
    tot =0 ;
    memset(deg,0,sizeof(deg));
}

void AddEdge(int u,int v)
{
    edges[tot] = (Edge){u,v,head[u]};
    head[u] = tot++;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int cas = 1;
    int N,M,K,u,v;
    while(scanf("%d %d %d",&N,&M,&K)==3){
        init();
        memset(deg,0,sizeof(deg));
        int L,R; scanf("%d %d",&L, &R);

        for(int i=1;i<=K;++i){
            scanf("%d %d",&u,&v);
            v+=N;
            AddEdge(u,v);
            deg[u]++;  deg[v]++;
        }

        for(int e=0;e<tot;++e){
            u = edges[e].u, v =edges[e].v;
            if(deg[u]>R || deg[v]>R){
                deg[u]--;
                deg[v]--;
            }
        }

        bool flag = true;

        for(int i=1;i<=N+M;++i){
            if(deg[i]<L || deg[i]>R){
                flag = false;
                break;
            }
        }
        printf("Case %d: ",cas++);
        if(flag) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/xiuwenli/p/9610142.html

时间: 2024-07-30 03:07:32

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心)的相关文章

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up sev

ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number

A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number NN as the supreme number if and only if each number made up of an non-empty subsequence of all

【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice&#39;s basics in digital electronics

[链接] 我是链接,点我呀:) [题意] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [题解] #include <bits/stdc++.h> #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define all(x) x.begin(),x.end(

ACM-ICPC 2018 沈阳赛区网络预赛

A. Gudako and Ritsuka 留坑 B. Call of Accepted 留坑 C. Convex Hull 留坑 D. Made In Heaven 留坑 E. The cake is a lie 留坑 F. Fantastic Graph 留坑 G. Spare Tire 留坑 H. Hamming Weight 留坑 I. Lattice's basics in digital electronics 留坑 J. Ka Chang 留坑 K. Supreme Number

Made In Heaven 2018 沈阳赛区网络预赛 D题

求第k短路 模板题 套模板即可 #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <queue> using namespace std; const int maxn=1005; const int maxe=100005; struct State{ int f; // f=g+dis dis表示当前点到终点的最短路径,即之前的

ACM-ICPC 2018 沈阳赛区网络预赛-I模拟题啊!!!

垃圾题,题目巨TM长...这题题意就是说给你一个16进制串,让你把每一位转成长度为4的2进制数,并把这些数连接起来,连接完成后,进行奇偶校验,把字符串切割成每个长度为9的字符串,然后计算前8位的 1的个数,,最后一位是校验位,如果1的个数为奇数 那么校验位应该是1,如果1的个数为偶数,那么校验位应该是0,如果满足,就保留验证的8位去掉校验位,否则去掉整个:然后给了M个字符串对应的ASCll,把验证位置留下来的东西,进行和字符串匹配,然后输出N个对应ASCll的字符??? 这题意很绕啊...不过纯

ACM-ICPC 2018 沈阳赛区网络预赛 Made In Heaven(K短路)题解

思路:K短路裸题 代码: #include<queue> #include<cstring> #include<set> #include<map> #include<stack> #include<string> #include<cmath> #include<vector> #include<cstdio> #include<iostream> #include<algori

ACM-ICPC 2018 沈阳赛区网络预赛 J. Ka Chang(树上分块+dfs序+线段树)

题意 链接:https://nanti.jisuanke.com/t/A1998 给出一个有根树(根是1),有n个结点.初始的时候每个结点的值都是0.下面有q个操作,操作有两种,操作1.将深度为L(根节点深度为0)的点的值全部增加X.操作2.查询以x为根的子树的结点值得和.其中N,Q<=1e5. 思路 因为这题是对某一深度的所有点加x,所以不是树链剖分. 我们可以先预处理一下dfs序,顺带把d[u]:u的深度.dd[x]:深度为x的点集求出来. 考虑分块,对某一深度分两种情况:1.这一深度的点的

ACM-ICPC 2018 沈阳赛区网络预赛 G. Spare Tire

这题很好啊,好在我没做出来...大概分析了一下,题目大概意思就是求 问所有满足1<=i<=n且i与m互素的ai之和 最开始我们队的做法是类似线性筛的方法去筛所有数,把数筛出来后剩下数即可,但是这样的是时间复杂度十分大,我们需要遍历每个质因 的倍数,这样最坏的复杂度是很大的1e8,因为我们需要把i的倍数筛到1e8,这样肯定不行,那么想想其他办法 我们想到了容斥-----(赛后想到的) 我们可以推处一个公式ai=i*i+i; 那么ai的前n项和Tn=n*(n+1)*(2*n+1)/6+n*(n+1