Codeforces 353E 贪心
题意:给你一张有向图,第i条边连接i号点和(i + 1) % n号点,问最多可以选择多少个点,使得这些点互相不可达。
思路:容易发现,如果某个边的集合点的数目大于等于2,那么就可以选出一个点,当然也可以出现多个1条边的集合相邻的情况(假设有m个),那么可以选择m / 2条边。
代码:
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define db double
#define pii pair<int, int>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1000010;
char s[maxn];
int main() {
int ans = 0;
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < n; i++) {
if(s[i] != s[(i + 1) % n]) {
if(s[i] != s[(i + 2) % n]) ans++;//下一个集合边数大于等于2,直接选择
else if(s[i] != s[(i + 3) % n]) {//出现了两个连续大小为1的集合,直接选择
i++, ans++;
}
}
}
printf("%d\n", ans);
}
Codeforces 353E 贪心的更多相关文章
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 570C 贪心
题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
- Codeforces 732e [贪心][stl乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...
- Codeforces 721D [贪心]
/* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...
- CodeForces - 424B (贪心算法)
Megacity Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
随机推荐
- AGC020C Median Sum
高端操作qaq 又双叒叕读错题了= = 然后重新读题发现不会做了 于是瞅了一波题解 我靠要不要这么暴力呜呜呜 直接bitset O(n^3/w)QAQ 就是f[i]表示i是否能被搞出来 然后我们先不看 ...
- 人生苦短_我用Python_def(函数)_004
# coding=utf-8 # function函数:内置函数 # 例如: len int extent list range str # print insert append pop rever ...
- 【leetcode】436. Find Right Interval
题目如下: 解题思路:题目要求的是对于任意一个区间i,要找出一个区间j,使得j的起点最接近i的终点.既然这样,我们可以把所有区间的终点组成一个列表,并按大小排序,使用二分查找就可以快速找到j区间.注意 ...
- cocos2D-X 打包
{ //首先有java jdk,android sdk,android ndk //用android studio import //匹配gradle 的版本 有些gradle可能下载不下来,不用慌 ...
- boost IOStreams
Boost.IOStreams provides numerous implementations of the two concepts. Devices which describes data ...
- PHP curl_file_create函数
curl_file_create — 创建一个 CURLFile 对象. 说明 CURLFile curl_file_create ( string $filename [, string $mime ...
- centos7下安装storm步骤
前言 真是后知后觉,最近忙也要学习,把以前丢的都要拾起来.原理懂不懂也把环境搭起来学习. 环境 centos7 jdk 1.8 zookeeper 3.4.13 storm 1.2.2 安装 ...
- [Repost] 常用素数
作者:Miskcoo(http://blog.miskcoo.com/2014/07/fft-prime-table) 如果 \(r\cdot 2^k+1\) 是个素数, 那么在 \(\bmod r\ ...
- python实现计时器(装饰器)
1.写一个装饰器,查看函数执行的时间 import time # 装饰器run_time,@run_time加在谁头上,谁就是参数fundef run_time(fun): start_time = ...
- Union比or快 Using UNION is faster when it comes to cases like scan two different column。
problem: 595. Big Countries A country is big if it has an area of bigger than 3 million square km or ...