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+;
const int N = 1e5 + ;
int n, m;
int a[N], b[N];
LL dp[N];
int main(){
scanf("%d%d", &n, &m);
for(int i = ; i <= m; ++i){
scanf("%d%d", &a[i], &b[i]);
if(i&) dp[i] = + i * (i - 1ll) / ;
else dp[i] = + i * (i-1ll)/ + i/ - ;
}
int k = m;
while(dp[k] > n) --k;
sort(b+, b++m, greater<int>());
LL ans = ;
for(int i = ; i <= k; ++i)
ans += b[i];
cout << ans << endl;
return ;
}

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

  1. 【codeforces 367C】Sereja and the Arrangement of Numbers

    [题目链接]:http://codeforces.com/problemset/problem/367/C [题意] 我们称一个数列a[N]美丽; 当且仅当,数列中出现的每一对数字都有相邻的. 给你n ...

  2. Codeforces 367

    A. Sereja and Algorithm 水题不解释. B. Sereja ans Anagrams 模p同余的为一组,随便搞. C. Sereja and the Arrangement of ...

  3. Codeforces 314 E. Sereja and Squares

    http://codeforces.com/contest/314/problem/E 题意: 原本有一个合法的括号序列 擦去了所有的右括号和部分左括号 问有多少种填括号的方式使他仍然是合法的括号序列 ...

  4. CodeForces - 367E:Sereja and Intervals(组合数&&DP)

    Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. ...

  5. [CodeForces]908D New Year and Arbitrary Arrangement

    设状态f[i][j]表示有i个a,j个ab的期望 发现如果i+j>=k的话就再来一个b就行了. #include <iostream> #include <cstdio> ...

  6. 【codeforces 314C】Sereja and Subsequences

    [题目链接]:http://codeforces.com/problemset/problem/314/C [题意] 让你从n个元素的数组中选出所有的不同的非递减子数列; 然后计算比这个子数列小的和它 ...

  7. codeforces 401 B Sereja and Contests【贪心】

    题意:给出最后的时间n,div 1必须和div2一起举行,并且div2的时间总是比div1大1 给出Sereja(只能参加div2)参加过的k场比赛的时间,问他最少错过了多少场div2,最多错过了多少 ...

  8. Codeforces #367 (Div. 2) D. Vasiliy's Multiset (trie 树)

    http://codeforces.com/group/1EzrFFyOc0/contest/706/problem/D 题目:就是有3种操作 + x向集合里添加 x - x 删除x元素,(保证存在 ...

  9. CodeForces #367 div2 D Trie

    题目链接:Vasiliy's Multiset 题意:这里有一个set容器,有三种操作,+ num, - num, ? num,分别代表往容器里加上num,或者拿走num,或着从容器里找一个数temp ...

随机推荐

  1. 【CocoaPods】ERROR: While executing gem ... Gem::DependencyError

    今天安装 CocoaPods 时遇到了这个问题. ERROR: While executing gem ... (Gem::DependencyError) Unable to resolve dep ...

  2. Spark Streaming自定义Receiver

    一 背景 Spark社区为Spark Streaming提供了很多数据源接口,但是有些比较偏的数据源没有覆盖,由于公司技术栈选择,用了阿里云的MQ服务ONS,要做实时需求,要自己编写Receiver ...

  3. springboot+kafka+邮件发送(最佳实践)

    导读 集成spring-kafka,生产者生产邮件message,消费者负责发送 引入线程池,多线程发送消息 多邮件服务器配置 定时任务生产消息:计划邮件发送 实现过程 导入依赖 <proper ...

  4. 第四次作业;创建raid5,源码编译安装;磁盘配额

    创建raid5 格式化 ext4 创建物理卷: 创建卷组: 创建逻辑卷: 格式化  ext4 挂载 开机自启动 创建raid配置文件 源码编译安装: 创建本地yum仓库 umount /dev/sr0 ...

  5. istio入门教程

    广告 | kubernetes各版本离线安装包 安装 安装k8s 强势插播广告 三步安装,不多说 安装helm, 推荐生产环境用helm安装,可以调参 release地址 如我使用的2.9.1版本 y ...

  6. 【游记】NOIP2019初赛

    声明 我的游记是一个完整的体系,如果没有阅读过往届文章,阅读可能会受到障碍. ~~~上一篇游记的传送门~~~ 前言 (编辑中) 文章推荐:[游记]NOIP2019复赛

  7. Spark 系列(七)—— 基于 ZooKeeper 搭建 Spark 高可用集群

    一.集群规划 这里搭建一个 3 节点的 Spark 集群,其中三台主机上均部署 Worker 服务.同时为了保证高可用,除了在 hadoop001 上部署主 Master 服务外,还在 hadoop0 ...

  8. HTML/CSS:block,inline和inline-block概念和区别

    总体概念 block和inline这两个概念是简略的说法,完整确切的说应该是 block-level elements (块级元素) 和 inline elements (内联元素).block元素通 ...

  9. AVL树(查找、插入、删除)——C语言

    AVL树 平衡二叉查找树(Self-balancing binary search tree)又被称为AVL树(AVL树是根据它的发明者G. M. Adelson-Velskii和E. M. Land ...

  10. Cause: java.lang.NumberFormatException: For input string: "D"

    异常:Cause: java.lang.NumberFormatException: For input string: "D" 问题回显: 原因分析:'D'只有1位,被认为是ch ...