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. 怎么把MVC的Controller拆分写到别的类库

    以为很难…… 其实直接继承Controller 并且按MVC_Controllser规则命名. 然后网站项目引用该项目即可.

  2. HTML5学习之文件操作(九)

    之前我们操作本地文件都是使用flash.silverlight或者第三方的activeX插件等技术,由于使用了这些技术后就很进行跨平台的处理,另外就是让我们的web应用依赖了第三方的插件,而不是很独立 ...

  3. golang exec Command

    package mainimport ( "fmt" "log" "os/exec")func main() { out, err := e ...

  4. hdu 2891 中国剩余定理

    从6点看到10点,硬是没算出来,早知道玩游戏去了,艹,明天继续看 不爽,起来再看,终于算是弄懂了,以后超过一个小时的题不会再看了,不是题目看不懂,是水平不够 #include<cstdio> ...

  5. Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树

    E. Sign on Fence   Bizon the Champion has recently finished painting his wood fence. The fence consi ...

  6. 网页或php服务连不上的几个可能原因

    1.webserver未启动. 2.php未启动. 3.url中端口和webserver配置文件中的不一致.

  7. 删除表数据drop、truncate和delete的用法

    说到删除表数据的关键字,大家记得最多的可能就是delete了 然而我们做数据库开发,读取数据库数据.对另外的两兄弟用得就比较少了 现在来介绍另外两个兄弟,都是删除表数据的,其实也是很容易理解的 老大- ...

  8. minix3(一)安装以及编辑文件

    作为一条通信狗,最近开始自学操作系统.听说用MINIX3学操作系统很好,就决定跟UCSB的课程试试. 首先在虚拟机上安装MINIX3. 开始用的VM Station,按照百度文库里安装minix3的教 ...

  9. CodeForces 19D Points(线段树+map)

    开始想不通,后来看网上说是set,就有一个想法是对每个x建一个set...然后又想直接建立两重的set就好,最后发现不行,自己想多了...  题意是给你三种操作:add (x y) 平面添加(x y) ...

  10. DrawerLayout的使用

    一:首先是DrawerLayout的布局 <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout& ...