Codeforces #Round 376 部分题解
A:
题目传送门:http://codeforces.com/problemset/problem/731/A
直接根据题意模拟即可
#include "bits/stdc++.h" using namespace std ;
typedef long long QAQ ; char s[ ] ; inline int Calc ( const char x , const char y ) {
if ( x > y ) return x - y ;
else return y -x ;
} inline int gmin ( int x , int y ) {
return x > y ? y : x ;
} int main ( ) {
scanf ( "%s" , s + ) ;
int len = strlen ( s + ) ; char now = 'a' ;
QAQ Ans = ;
for ( int i= ; i<=len ; ++i ) {
char next = s[ i ] ;
int cost = gmin( Calc ( now , next ) , - Calc ( now , next ) ) ;
Ans += cost ;
now = s[ i ] ;
}
cout << Ans << endl ;
return ;
}
B:
题目传送门:http://codeforces.com/problemset/problem/731/B
贪心
#include <iostream>
#include <cstdio>
#include <fstream>
#include <sstream> using namespace std ;
const int maxN = 2e5 + 1e3 ;
const double eps = 1e- ; int arr [ maxN ] ; int INPUT ( ) {
int x = , f = ; char ch = getchar ( ) ;
while ( ch < '' || ch > '' ) { if ( ch == '-' ) f = - ; ch = getchar ( ) ; }
while ( ch <='' && ch >= '' ){ x = ( x << ) + ( x << ) + ch - '' ; ch = getchar ( ) ; }
return x * f ;
} int main ( ) {
int N = INPUT ( ) ;
for ( int i= ; i<=N ; ++i ) {
arr[ i ] = INPUT ( ) ;
}
for ( int i= ; i<=N+ ; ++i ) {
if ( arr[ i ] < ) {
goto Fail ;
}
if ( arr[ i ] % == ){
-- arr[ i + ] ;
}
}
cout << "YES" << endl ;
goto End ;
Fail :
cout << "NO" << endl ;
End:
return ;
}
C:
题目传送门:http://codeforces.com/problemset/problem/731/C
将每个联通袜子分量加入一个冰炸鸡,用带权的冰炸鸡维护。最小染色数等于总共个数 - 颜色袜子最多的个数。
#include "bits/stdc++.h" using namespace std ;
const int maxN = 2e5 + 1e3 ;
typedef long long QAQ ; int c[ maxN ] , t1[ maxN ] , t2[ maxN ] , father[ maxN ] , size[ maxN ] ;
map <int ,int>mp[ maxN ] ;
QAQ Ans ; int getfa ( const int x ) { return father[ x ] == x ? x : father[ x ] = getfa ( father[ x ] ) ; }
inline int gmin ( const int x , const int y ) { return x > y ? y : x ; }
inline int gmax ( const int x , const int y ) { return x > y ? x : y ; }
void Set_Init ( const int n ) { for ( int i= ; i<=n ; ++i ) father[ i ] = i , size[ i ] = ; }
inline void Union_Set ( int x , int y ) { father[ x ] = y ; size[ y ] += size [ x ] ; } inline int INPUT ( ) {
int ret = , f = ; char ch = getchar( ) ;
while ( ch < '' || '' < ch ) { if ( ch == '-' ) f = - ; ch = getchar ( ) ; }
while ( '' <= ch && ch <= '' ) { ret = ( ret << ) + ( ret << ) + ch - '' ; ch = getchar ( ) ; }
return ret * f ;
} int main ( ) {
int N = INPUT ( ) , M = INPUT ( ) , K = INPUT ( ) ;
for ( int i= ; i<=N ; ++i )
c[ i ] = INPUT ( ) ;
Set_Init ( N ) ;
for ( int i= ; i<=M ; ++i ) {
t1[ i ] = INPUT ( ) , t2[ i ] = INPUT ( ) ;
int px = getfa ( t1[ i ] ) ;
int py = getfa ( t2[ i ] ) ;
if ( px != py ) Union_Set ( px , py ) ;
}
for ( int i= ; i<=N ; ++i ) ++mp[ getfa ( i ) ][ c[ i ] ] ;
for ( int i= ; i<=N ; ++i ) {
if ( getfa ( i ) == i ) {
int temp = ;
map <int , int>::iterator It ;
for ( It = mp[ i ].begin( ) ; It != mp[ i ].end ( ) ; ++It ) {
temp = gmax( temp, It -> second ) ;
}
Ans += size[ i ] - temp ;
}
}
cout << Ans << endl ;
return ;
}
Codeforces #Round 376 部分题解的更多相关文章
- Codeforces #Round 376 F 题解
F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
- Codeforces Round #539 Div1 题解
Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...
- Educational Codeforces Round 64 部分题解
Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...
- Educational Codeforces Round 64部分题解
Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...
- Codeforces Round div2 #541 题解
codeforces Round #541 abstract: I构造题可能代码简单证明很难 II拓扑排序 III并查集 启发式排序,带链表 IV dp 处理字符串递推问题 V 数据结构巧用:于二叉树 ...
- [Codeforces Round #461 (Div2)] 题解
[比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys [算法] 当y = 0 , 不可以 当 ...
- Educational Codeforces Round 63部分题解
Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...
随机推荐
- .net学习之委托和事件
1.什么是委托通俗的说:委托就是一个能够存储符合某种格式(方法签名)的方法的指针的容器上传图片: 2.委托语法准备一个方法:string Hello(string userName){} string ...
- Web框架之Tornado
概述 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过为了 ...
- python 之socket 网络编程
socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. socket起源于Un ...
- Go 中的反射要点
简介 反射是元数据编程的一种形式,指的是程序获得本身结构的一种能力.不同语言的反射模型实现不一样,本文中的反射,仅仅指的是Go语言中的反射模型. 类型以及接口 这个基本概念需要清晰,这里不详细展开. ...
- JavaScript - 事件流
事件流 事件冒泡就是事件沿DOM树向上传播,在没一级节点上都会发生,直至传播到document对象. 事件捕获正好相反,但是老版本的浏览器不支持,因此很少有人使用事件捕获. 事件处理程序 HTMl 事 ...
- W:Failed to fetch http://archive.ubuntukylin.com:10006/ubuntukylin/dists/pre
由于用ubuntu的时候装了几个ubuntukylin的软件(像搜狗拼音for linux),于是最近总是蹦出一个红色的三角提示,说无法更新,虽说不影响使用但是还是很不爽.解决方法记录如下: 进入系统 ...
- ASP.NET 5探险(1):Azure中配置连接字符串、独立项目执行EF7数据迁移
(此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:我开始把ASP.NET 5用于生产系统开发已经有1个多月了,也填了一些坑积累了一些经验,从今天开始会陆陆续 ...
- C++Primer快速浏览笔记-类型转换
bool b = 42; // _b is true_ int i = b; // _i has value 1_ i = 3.14; // _i has value 3_ double pi = i ...
- 强化的单例属性_Effective Java
Singleton指的是仅仅被实例化一次的类,比如唯一的系统组件等,成为Singleton的类测试起来也比较困难. 常用的方法: 1.公有静态final域+私有构造器 public class Egg ...
- Alcatraz安装 不能用解决方案
1.安装 1>Github上下载Alcatraz,下载地址:https://github.com/supermarin/Alcatraz 2>Alcatraz是xcode的插件,这个插件 ...