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 部分题解的更多相关文章

  1. Codeforces #Round 376 F 题解

    F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

  3. Codeforces Round #545 Div1 题解

    Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...

  4. Codeforces Round #539 Div1 题解

    Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...

  5. Educational Codeforces Round 64 部分题解

    Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...

  6. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  7. Codeforces Round div2 #541 题解

    codeforces Round #541 abstract: I构造题可能代码简单证明很难 II拓扑排序 III并查集 启发式排序,带链表 IV dp 处理字符串递推问题 V 数据结构巧用:于二叉树 ...

  8. [Codeforces Round #461 (Div2)] 题解

    [比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys          [算法] 当y = 0 ,   不可以 当 ...

  9. Educational Codeforces Round 63部分题解

    Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...

随机推荐

  1. GMap.Net开发之技巧小结

    1.在GMap地图上,如果要让添加的图标(Marker)有个高亮(highlight)的效果,可以在MouseOver到Marker的时候设置Marker外观效果. 如果要让图标有个报警闪烁的效果,可 ...

  2. 单机安装Hadoop环境

    目的 这篇文档的目的是帮助你快速完成单机上的Hadoop安装与使用以便你对Hadoop分布式文件系统(HDFS)和Map-Reduce框架有所体会,比如在HDFS上运行示例程序或简单作业等. 先决条件 ...

  3. jquery判断当前设备是手机还是电脑并跳转

    <script type="text/javascript"> var commonURL = 'http://xxxx.com/'; function mobile_ ...

  4. hdu 3709 数位dp

    数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...

  5. Java 对象序列化(Serialization Object)

    官网文档:https://docs.oracle.com/javase/tutorial/jndi/objects/serial.html 优秀博客: http://www.cnblogs.com/g ...

  6. 在IIS上部署SSL

    背景: 在处理DropboxAPI开发时,其重定向的URL地址必须是https的[除了localhost],不得已在自己网站上加了ssl,下面简单介绍下添加自签名证书,毕竟只是临时使用. 1.打开II ...

  7. cocos2dx游戏开发——别踩白块学习笔记(一)——Block类

    一.Block类介绍 当然啦,Block类在这个游戏里就是必需品= =,因为整体都是由这个搞出来的,所以我们可以把游戏需要实现的功能都放在这里. 主要有下面这些功能(经典模式): 1.创建一个Bloc ...

  8. 【hibernate】 hibernate的主键策略

    今天使用maven生成一个sping+springMVC+hibernate 的项目,报错如下: 错误提示呢:不能解释这个id的生成策略[uuid.string].就是uuid.string这个hib ...

  9. caffe配置python环境

    make pycaffe 在python中import caffe

  10. 利用pushState开发无刷页面切换

    转载:http://www.cnblogs.com/flash3d/archive/2013/10/23/3384823.html 实现目标 页面的跳转(前进后退,点击等)不重新请求页面 页面URL与 ...