zoukankan      html  css  js  c++  java
  • CodeForces 367 C Sereja and the Arrangement of Numbers 欧拉回路

    Sereja and the Arrangement of Numbers

    题解:

    ummm。

    在一副图中,如果全部点的度数是偶数/只有2个点是奇数,则能一笔画。

    考虑图的点数k为奇数的时候,那么每个点的度数都是偶数点,所以就是可以一笔画,答案为 1 +k * (i - kll) / 2;

    k为偶数的时候,所有的点是奇数点,我们保留2个点是奇数点,将其他的点改为偶数点,就可以一笔画了。  1 +k * (i - kll) / 2 + k/2 - 1.

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
    #define LL long long
    #define ULL unsigned LL
    #define fi first
    #define se second
    #define pb push_back
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define lch(x) tr[x].son[0]
    #define rch(x) tr[x].son[1]
    #define max3(a,b,c) max(a,max(b,c))
    #define min3(a,b,c) min(a,min(b,c))
    typedef pair<int,int> pll;
    const int inf = 0x3f3f3f3f;
    const int _inf = 0xc0c0c0c0;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const LL _INF = 0xc0c0c0c0c0c0c0c0;
    const LL mod =  (int)1e9+7;
    const int N = 1e5 + 100;
    int n, m;
    int a[N], b[N];
    LL dp[N];
    int main(){
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= m; ++i){
            scanf("%d%d", &a[i], &b[i]);
            if(i&1) dp[i] = 1 + i * (i - 1ll) / 2;
            else dp[i] = 1 + i * (i-1ll)/2 + i/2 - 1;
        }
        int k = m;
        while(dp[k] > n) --k;
        sort(b+1, b+1+m, greater<int>());
        LL ans = 0;
        for(int i = 1; i <= k; ++i)
            ans += b[i];
        cout << ans << endl;
        return 0;
    }
    View Code
  • 相关阅读:
    软件工程实践总结作业
    SDN第4次上机作业
    SDN第四次作业
    SDN第三次上机作业
    SDN第三次作业
    SDN第二次上机作业
    SDN第一次上机作业
    免费自动生成字幕工具推荐,啃生肉啊(6.12更新)
    博客园美化,自定义你的博客,css+html (iframe)
    找质数、素数_算法优化(C++)
  • 原文地址:https://www.cnblogs.com/MingSD/p/10868609.html
Copyright © 2011-2022 走看看