Codeforces 965 枚举轮数贪心分糖果 青蛙跳石头最大流=最小割思想 trie启发式合并
A
/*#include<cstring>#include<algorithm>#include<queue>#include<vector>#include<cstdio>#include<cmath>#include<iostream>*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = ;
int main()
{
int k, n, s, p;
cin >> k >> n >> s >> p;
int ans = n / s + ( - (n % s == ));
ans *= k;
cout << ans / p + ( - (ans % p == )) << endl;
return ;
}
B
/*#include<cstring>#include<algorithm>#include<queue>#include<vector>#include<cstdio>#include<cmath>#include<iostream>*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = ;
char f[][];
int ans;
int aimc = ;
int aimr = ;
int flag;
int now;
int main()
{
int n, k;
cin >> n >> k;
for (int i = ; i <= n; i++)
{
scanf("%s", f[i] + );
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
if (f[i][j] == '#')
{
continue;
}
now = ;
for (int dx = j - k + ; dx <= j; dx++)
{
if (dx + k > n + )
{
break;
}
if (dx < )
{
continue;
}
flag = ;
for (int w = dx; w <= dx + k - ; w++)
{
if (f[i][w] == '#')
{
flag = ;
break;
}
}
if (flag)
{
now++;
}
}
for (int dy = i - k + ; dy <= i; dy++)
{
if (dy + k > n + )
{
break;
}
if (dy < )
{
continue;
}
flag = ;
for (int w = dy; w <= dy + k - ; w++)
{
if (f[w][j] == '#')
{
flag = ;
break;
}
}
if (flag)
{
now++;
}
}
if (now > ans)
{
ans = now;
aimc = i, aimr = j;
}
}
}
cout << aimc << " " << aimr << endl;
return ;
}
C
首先用贪心的思想可以知道 如果是一整轮一整轮地分 肯定是X越大越好
当加上题目剩下的不小于X的也要分的时候 最佳肯定是当X尽量大且最后多分给A1一次的时候最佳
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n,k,m,d;
cin >> n >> k >> m >> d;
ll anser=;
for(ll i=;i<=d;i++)
{
if(i!=)
{
ll now=n/(i-);
if(now<k)
continue;
}
ll sum=n/(k*i-k+);
if(sum>m)
{
if(m*i>=(n-n%m)/k)
sum=m;
else
continue;
}
anser=max(anser,sum*i);
}
cout<<anser<<endl;
return ;
}
D
这题的建模是一个网络流 第i个石头对每个[i+1,i+l]都有一条容量为a[i]的边 源点与左岸相连 汇点与右岸相连 算最大流
但其实可以用最大流最小割思想简化 因为你跳的次序并不会影响最后的答案 所以我们可以认定每次全部青蛙都在一个长度为L的窗口内
所以答案就是min(sum(ai~ai+l)) 即视连续L个石头为一个节点 前一个节点有指向后一个节点sum(ai~ai+l)的边 所以最大流是最小的那条边
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[];
int main()
{
int n, l;
cin >> n >> l;
n--;
int minn = INT_MAX;
int sum = ;
for (int i = ; i < n; i++)
{
cin >> a[i];
}
for (int i = ; i < l; i++)
{
sum += a[i];
}
minn = sum;
for (int i = l; i <= n - ; i++)
{
sum -= a[i - l];
sum += a[i];
minn = min(minn, sum);
}
cout << minn << endl;
return ;
}
E
Codeforces 965 枚举轮数贪心分糖果 青蛙跳石头最大流=最小割思想 trie启发式合并的更多相关文章
- JAVA-小青蛙跳石头游戏
游戏摘自微信传的手机网页版小游戏,我拿来做成了JAVA的界面版,但是没有去做素材,,直接拿方块代替小青蛙.游戏原址就不分享了,只能在手机上打开. 下面是源码: /* * Main.java * */ ...
- Atcoder Regular Contest 125 E - Snack(最小割转化+贪心)
Preface: 这是生平第一道现场 AC 的 arc E,也生平第一次经历了 performance \(\ge 2800\),甚至还生平第一次被 hb 拉到会议里讲题,讲的就是这个题,然鹅比较尬 ...
- [LeetCode] Candy (分糖果),时间复杂度O(n),空间复杂度为O(1),且只需遍历一次的实现
[LeetCode] Candy (分糖果),时间复杂度O(n),空间复杂度为O(1),且只需遍历一次的实现 原题: There are N children standing in a line. ...
- Codeforces 965 D. Single-use Stones(思维)
Codeforces 965 D. Single-use Stones 题目大意: 有一条河宽度为w,河上有一些石头,给出一组数(编号1~w-1),其中a[i]代表与河一岸距离为i的石头数量.每只青蛙 ...
- CSDN 分糖果算法的思路和求助
昨天晚上 在csdn上做了一道分糖果的题目,我自个测的是没有问题,但是提交答案后,老失败,提示 你的程序正常运行并输出了结果,但是答案错误你的程序输出结果与测试数据中的输出结果不符 我先把自个思路说一 ...
- codeforces 704B - Ant Man 贪心
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...
- hunnu11543:小明的烦恼——分糖果
Problem description 小明在班里一直是个非常公正的孩子.这点同学和老师都非常清楚,这不,老师每周都会从家里带来一些糖果.然后叫小明把糖果分给其它小朋友,但这个班里的同学都有一个非 ...
- C语言 · 分糖果
历届试题 分糖果 时间限制:1.0s 内存限制:256.0MB 问题描述 有n个小朋友围坐成一圈.老师给每个小朋友随机发偶数个糖果,然后进行下面的游戏: 每个小朋友都把自己的糖果分一 ...
- CodeForces - 50A Domino piling (贪心+递归)
CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...
随机推荐
- Boston House Price with Scikit-Learn
Boston House Price with Scikit-Learn Data Description >>> from sklearn.datasets import load ...
- IPython4_Notebook
目录 目录 前言 系统软件 Setup IPython Setup IPython Setup Notebook 临时指定镜像源 Install pyreadline Install pyzmq In ...
- 阶段3 2.Spring_04.Spring的常用注解_4 由Component衍生的注解
为什么要使用者三个注解 Controller:表现层 Service:业务层 Repository:持久层 在这里就是用Controller 运行也没问题 用Service Repository同样也 ...
- ALV程序设计
ALV 全称SAP LIST VIEW, 是SAP所提供的一个强大的数据报表显示工具. ALV显示格式分为GRID及LIST两种,两者所显示数据一致, GRID模式在每个输出字段提供选择按钮,允许用 ...
- Activity启动模式分类(一)
standerd 默认模式,每次启动Activity都会创建一个新的Activity实例. 比如:现在有个A Activity,我们在A上面启动B,再然后在B上面启动A,其过程如图所示: single ...
- github局部不同图片合并插件
用于解决游戏开发时,一套图里有局部地区图片不同其他地方相同,导致资源重复过大的问题 地址:https://github.com/Elringus/SpriteDicing
- 描述什么是springboot
Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作<Expert One-On-One J2EE Developme ...
- python+selenium下载文件——Chrome
from selenium import webdriver import time options = webdriver.ChromeOptions() prefs = { 'profile.de ...
- 牛客小白月赛13-H(单调栈+树状数组)
题目链接:https://ac.nowcoder.com/acm/contest/549/H 题意:给一个柱状图,包括每个矩阵的宽度和高度,求能组成的最大矩阵的面积. 思路:显然最大矩阵的高一定为n个 ...
- spring boot-18.使用dubbo发布分布式服务
我们新建两个项目分别模拟服务的提供者和服务的消费者,spring boot 集成dubbo主要分为以下几个步骤: 1.安装zookeeper 推荐使用docker 安装,使用以下几个命令即可完成 (1 ...