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;
}

原文地址:https://www.cnblogs.com/MingSD/p/10868609.html

时间: 2024-08-01 17:04:06

CodeForces 367 C Sereja and the Arrangement of Numbers 欧拉回路的相关文章

CodeForces - 367C Sereja and the Arrangement of Numbers

题目大意: 要求构建一个长为n的数组,其中每两种不同的元素必须有一对是相邻的 然后给出m个交易,如果数组中有q[i]这个元素,就给w[i]元钱,求最多能得到多少钱? 具体思路: 先求出有x个不同元素的最小长度,然后给钱排个序就好啦 怎么求最小长度呢?可以把数组看成一个完全图的一条路径 最小长度大概就是一个欧拉路径啦,奇偶分类讨论一下就好啦 AC代码 #include<bits/stdc++.h> #define int long long using namespace std; int a[

Codeforces Round #597 (Div. 2) A. Good ol&#39; Numbers Coloring

链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: 0,1,2,-. Given two integers a and b (1≤a,b≤104). We paint all the numbers in increasing number first we paint 0, then we paint 1, then 2 and so on. Ea

CodeForces #367 div2 D Trie

题目链接:Vasiliy's Multiset 题意:这里有一个set容器,有三种操作,+ num, - num, ? num,分别代表往容器里加上num,或者拿走num,或着从容器里找一个数temp使得temp^num的值最大.输出这个最大值. 思路:对于XOR操作,一般都要拆位考虑,拆完之后用Trie或者线段树维护,然后,这个题把每个数的二进制30位(前面不够的用0补全)插入Trie,查询的时候,对于每一位先尝试往相反的方向走,因为异或 只要越高位 相反值越大,然后再尝试往相同的方向走.最后

Codeforces 908D New Year and Arbitrary Arrangement(概率DP,边界条件处理)

题目链接  Goodbye 2017 Problem D 题意  一个字符串开始,每次有$\frac{pa}{pa+pb}$的概率在后面加一个a,$\frac{pb}{pa+pb}$的概率在后面加一个$b$. 求当整个串中有至少$k$个$ab$的时候(不需要连续,下同),字符串中$ab$个数的期望. 设$f[i][j]$为字符串有$i$个$a$,$j$个$ab$的时候字符串中$ab$个数的期望 设$p = \frac{pa}{pa+pb}$, $q = \frac{pb}{pa+pb}$ 那么对

Codeforces Round #114 (Div. 1) C Wizards and Numbers

题目链接:Wizards and Numbers 题意:有两个数字a, b,假设 a>b,两个玩家进行游戏,有两种操作:1. 令 a=a-b^k,k为正数,且需要保证操作后 a 仍然非负:2. 令 a=a%b.最终有一个人无法操作(存在一个数为0)的时候便输了. 题解:如果只有操作2就是一个辗转相除法,实际上加上了操作1,执行的过程中也一定会出现辗转相除法种每轮的数字情况.所以以辗转相除法的每轮情况作为分段点,讨论其是必胜态还是必败态,首先(t, 0) 一定是必败态,所以其上一层的状态一定是必胜

Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp

D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] 需要用SOSdp #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define

Codeforces Round #215 (Div. 1)

A Sereja and Algorithm 题意:给定有x,y,z组成的字符串,每次询问某一段s[l, r]能否变成变成zyxzyx的循环体. 分析: 分析每一段x,y,z数目是否满足构成循环体,当然长度<3的要特判. 代码: 1 #include <bits/stdc++.h> 2 #define in freopen("solve_in.txt", "r", stdin); 3 #define pb push_back 4 5 using n

CodeForces 380A Sereja and Prefixes

A. Sereja and Prefixes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm

[2016-02-05][CF][380A][Sereja and Prefixes]

[2016-02-05][CF][380A][Sereja and Prefixes] CodeForces - 380A Sereja and Prefixes Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status Description Sereja loves number sequences very much. That's why he decided to mak