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. 【hdu 1060】【求N^N最低位数字】

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. Go的基本示例

    有空可以看看, 不知能不能超越JAVA的作法. hello.go package main import "fmt" func main() { s := "hello& ...

  3. hdu 2203:亲和串(水题,串的练习)

    亲和串 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. javascript中求浏览器窗口可视区域兼容性写法

    1.浏览器窗口可视区域大小 1.1 对于IE9+.Chrome.Firefox.Opera 以及 Safari:•  window.innerHeight - 浏览器窗口的内部高度•  window. ...

  5. 华为Mate8 NFC 时好时坏,怎么解决呢?

    拿起手机朝桌子上磕几下,nfc就好用了.这是花粉总结的,我也试过,很灵.注意要带套,摄像头朝下,头部低一点往下磕.因为nfc芯片在头部,估计是接触不良.

  6. Solr入门之(2)快速启动:第一个例子

    Solr作为一个web应用来启动,因此需要JDK支持,需要WEB容器,本文环境如下: JDK6.0或以上(环境变量设置等不再赘述) Tomcat-6.0.35或以上(自行下载) apache-solr ...

  7. thinkphp分页样式

    html代码: <div class="pages">{$page}</div> css代码: .pages{ width:100.5%; text-ali ...

  8. AgileEAS.NET SOA 中间件平台5.2版本下载、配置学习(三):配置ActiveXForm运行环境

    一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...

  9. 直传文件到Azure Storage的Blob服务中

    (此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:为了庆祝获得微信公众号赞赏功能,忙里抽闲分享一下最近工作的一点心得:如何直接从浏览器中上传文件到Azure ...

  10. HDU 1561 The more, The Better 树形DP

    The more, The Better Problem Description   ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M ...