CodeForces 998B Cutting(贪心)
https://codeforces.com/problemset/problem/998/B


简单贪心题
代码如下:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxn=1e5+;
using namespace std; int a[];
int b[];//如果可分,存放差值 int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
int x=;//前面奇数的个数
int y=;//前面偶数的个数
int cnt=;//b数组下标计数器
for(int i=;i!=n;i+=)
{
a[i-]%==? x++ : y++;
a[i-]%==? x++ : y++;
if(x==y)//该数后面的间隔可分
b[cnt++]=max(a[i],a[i-])-min(a[i],a[i-]);
}
sort(b,b+cnt);
int num=;
for(int i=;i<cnt;i++)
{
if(m>=b[i])
{
num++;
m-=b[i];
}
else
break;
}
printf("%d\n",num);
return ;
}
CodeForces 998B Cutting(贪心)的更多相关文章
- CodeForces - 158B.Taxi (贪心)
CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一 ...
- codeforces 724D(贪心)
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...
- Codeforces 626G Raffles(贪心+线段树)
G. Raffles time limit per test:5 seconds memory limit per test:256 megabytes input:standard input ou ...
- Cut 'em all! CodeForces - 982C(贪心dfs)
K - Cut 'em all! CodeForces - 982C 给一棵树 求最多能切几条边使剩下的子树都有偶数个节点 如果n是奇数 那么奇数=偶数+奇数 不管怎么切 都会有奇数 直接打印-1 贪 ...
- CodeForces - 940E - Cashback +贪心+DP
传送门:CodeForces - 940E - Cashback 题意:在一个长度为n的数组中,可以分出长度为 k 连续的多个数组b(每个数组 b 的 k 可不相同),然后,可以对每个数组 b 进行删 ...
- Codeforces 515C 题解(贪心+数论)(思维题)
题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...
- CodeForces 485C Bits[贪心 二进制]
C. Bits time limit per test1 second memory limit per test256 megabytes inputstandard input outputsta ...
- codeforces 732E(贪心)
题目链接:http://codeforces.com/contest/732/problem/E 题意:有n台计算机,m个插座,每台计算机有一个值a[i],每个插座有一个值b[i],每个插座最多只能对 ...
- Codeforces 732D [二分 ][贪心]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: n天进行m科考试,每科考试需要a的复习时间,n天每天最多可以考一科.并且指定哪天考哪科. 注意考试那天不能复习. 问最少需要多少天可全部通过考试. ...
随机推荐
- Distributed--2PC和3PC
参考 https://blog.csdn.net/lnho2015/article/details/78685503 https://www.cnblogs.com/hubaoxi/p/6867203 ...
- 【pwnable.kr】bof
pwnable从入门到放弃,第三题. Download : http://pwnable.kr/bin/bofDownload : http://pwnable.kr/bin/bof.c Runnin ...
- (一)IOC基础推导及理论
环境准备:见java环境搭建,新建maven项目 1.写一个UserDao接口 public interface UserDao { public void getUser(); } 2.再写Dao的 ...
- HTML条件注释判断<!--[if IE] ![endif]-->
很多网页中会见到这样的代码: <!--[if IE 7]> <![endif]--> /*或者*/ <!--[if lt IE 9]> <![endif]-- ...
- find_element_by_xpath()的6种方法
Xpath (XML Path Language),是W3C定义的用来在XML文档中选择节点的语言 一:从根目录/开始 有点像Linux的文件查看,/代表根目录,一级一级的查找,直接子节点,相当于cs ...
- 洛谷 P5662 纪念品
题目传送门 解题思路: 一道DP,完全背包,不过有点不同于模板.因为本题的每件物品可自由在不同的时间买卖,且不同时间价格不同. 这道题的关键在于要明白一个非常傻逼的性质,就是我在某天买了第i个物品,然 ...
- 阿里云云服务器测试uwgis的基本流程
基本背景 uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI / uwsg ...
- Java时间格式化年-月-日-时间
Date d = new Date(); System.out.println(d); //Sat Mar 16 20:58:56 CST 2019 System.out.println(d.toLo ...
- maven打包 invalid entry size Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.14.RELEASE:repackage (default) on project
打包失败,但是不知是具体是什么引起得,使用mvn -e clean package,定位到报错得代码 在定位到代码,打上断点,使用maven 打包debug模式 找到dubbo.properties, ...
- 分享-QQ/微信/微博(环境搭建)
QQ环境搭建