CodeForces 367 C Sereja and the Arrangement of Numbers 欧拉回路

Posted mingsd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于CodeForces 367 C Sereja and the Arrangement of Numbers 欧拉回路的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces - 367C Sereja and the Arrangement of Numbers

CodeForces 380C Sereja and Brackets(扫描线+树状数组)

[Codeforces 425A] Sereja and Swaps

Codeforces 425A Sereja and Swaps(暴力枚举)

「专题训练」Hard problem(Codeforces Round #367 Div. 2 C)

Sereja and Swaps CodeForces - 426C