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. APP消息推送:通知和透传

    目前市场上的消息推送方式有两种:通知和透传.什么是透传?透传即是透明传送,即传送网络无论传输业务如何,只负责将需要传送的业务传送到目的节点,同时保证传输的质量即可,而不对传输的业务进行处理.透传消息, ...

  2. 【翻译三】java-并发之线程对象和实现

    Thread Objects Each thread is associated with an instance of the class Thread. There are two basic s ...

  3. MYSQL建表语法(主键,外键,联合主键)

    在看<Learning SQL>第二版, 慢慢打实SQL的基础. 建表一: ), lname ), gender ENUM(), city ), state ), country ), p ...

  4. NBU官方Doc網址https://www.veritas.com/support/en_US/article.DOC5332

    NBU(NetBackup) 7.0之後的版本官方文檔鏈接地址: https://www.veritas.com/support/en_US/article.DOC5332

  5. jQuery实现长按按钮触发事件的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 获取当前IP地址,跳转到对应城市网站。

    index.php文件 1,通过获取当前IP地址, 2,调用新浪AIP,获取到当前城市. 3,将中文转换为拼音后跳转. <?php include './pinyin.php'; //获取当前i ...

  7. SQL常用查询语句及函数

    1.日期匹配_获取时间差 select datediff(dd,getdate(),'12/25/2006')  --计算从今天到12/25/2006还有多少个月 2.不能通过IP连接数据库 在数据库 ...

  8. windows多线程详解

    转自:http://blog.csdn.net/zhouxuguang236/article/details/7775232 在一个牛人的博客上看到了这篇文章,所以就转过来了,地址是http://bl ...

  9. Android学习网站

    1 <老罗Android应用开发视频教程> http://www.mobiletrain.org/about/news/android_video2.html

  10. Codeforces Round #14 D. Two Paths(求树上两条不相交的路径的乘积最大值)

    题目链接:  http://codeforces.com/problemset/problem/14/D 思路:直接枚举每一天路径的两端,然后求以每一端为树根的树上最长路径,然后相乘就可以了. # ...