B. Math Show 暴力 C - Four Segments
这个题目直接暴力,还是有点难想,我没有想出来,有点思维。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <list>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
int a[110], vis[110];
int sum[110];
int main()
{
int n, k, m, ans = 0, sum = 0;
scanf("%d%d%d", &n, &k, &m);
for (int i = 1; i <= k; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
sort(a + 1, a + 1 + k);
for (int i = 0; i <= n; i++) {
int res = m - i * sum;
if (res < 0) break;
int num = (k + 1)*i;
for (int j = 1; j <= k; j++) {
if (res >= a[j] * (n - i)) {
res -= a[j] * (n - i);
num += n - i;
}
else {
num += res / a[j];
break;
}
}
ans = max(ans, num);
}
printf("%d\n", ans);
return 0;
}
这个题目我觉得还是有点难,这个题目求 res= sum[1,x-1] - sum[x,y-1] + sum[y,z-1] -sum[z, n] 的最大值
暴力枚举中间的y,然后两边贪心求x , z
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <list>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 5e3 + 10;
ll sum[maxn], a[maxn]; int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), sum[i] = sum[i - 1] + a[i];
ll ans = 0, x = 1, y = 1, z = 1;
for(int i=1;i<=n;i++)
{
ll res1 = 0, mark1 = 1;
for (int j = i; j <= n + 1; j++) {
ll num = sum[j - 1] * 2 - sum[i - 1] - sum[n];
if (num > res1) res1 = num, mark1 = j;
}
ll res2 = 0, mark2 = 1;
for (int j = 1; j <= i; j++) {
ll num = 2 * sum[j - 1] - sum[i - 1];
if (num > res2) res2 = num, mark2 = j;
}
if(res1+res2>ans)
{
ans = res1 + res2;
x = mark2, y = i, z = mark1;
// printf("ans=%d\n", ans);
}
}
printf("%lld %lld %lld\n", x - 1, y - 1, z - 1);
return 0;
}
B. Math Show 暴力 C - Four Segments的更多相关文章
- hdu 5595 GTW likes math(暴力枚举查询)
思路:直接暴力枚举区间[l,r]的整数值,然后max和min就可以了. AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000 ...
- HDU 6063 17多校3 RXD and math(暴力打表题)
Problem Description RXD is a good mathematician.One day he wants to calculate: ∑i=1nkμ2(i)×⌊nki−−−√⌋ ...
- 实践 HTML5 的 CSS3 Media Queries
先来介绍下 media,确切的说应该是 CSS media queries(CSS 媒体查询),媒体查询包含了一个媒体类型和至少一个使用如宽度.高度和颜色等媒体属性来限制样式表范围的表达式.CSS3 ...
- 基于 CSS3 Media Queries 的 HTML5 应用
先来介绍下 media,确切的说应该是 CSS media queries(CSS 媒体查询),媒体查询包含了一个媒体类型和至少一个使用如宽度.高度和颜色等媒体属性来限制样式表范围的表达式.CSS3 ...
- cesium and three.js【转】
https://blog.csdn.net/zhishiqu/article/details/79077883 这是威尔逊Muktar关于整合Three.js与铯的客人帖子.Three.js是一个轻量 ...
- JS闪电打字特效
HTML <div class="page page-thunder-to-text"> <input id="input" type=&qu ...
- Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)
The only difference between easy and hard versions is a number of elements in the array. You are giv ...
- HDU 6697 Closest Pair of Segments (计算几何 暴力)
2019 杭电多校 10 1007 题目链接:HDU 6697 比赛链接:2019 Multi-University Training Contest 10 Problem Description T ...
- E1. Array and Segments (Easy version)(暴力) && E2. Array and Segments (Hard version)(线段树维护)
题目链接: E1:http://codeforces.com/contest/1108/problem/E1 E2:http://codeforces.com/contest/1108/problem ...
随机推荐
- awk线程号
for i in `ps|grep [a]out|awk '{print $1}'` do kill -9 "$i" done
- @suppressWarnings("unchecked") java 中是什么意思 (一般放dao查询方法上)
J2SE 提供的最后一个批注是 @SuppressWarnings.该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默. 一点背景:J2SE 5.0 为 Java 语言增加 ...
- 如何在Ubuntu 18.04上安装Nginx
Nginx功能之强大,想必大家比我更清楚. 百度百科:Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务.Nginx是由伊戈尔 ...
- abp(net core)+easyui+efcore实现仓储管理系统——入库管理之九(四十五)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- search(7)- elastic4s-search-filter模式
现在我们可以开始探讨ES的核心环节:搜索search了.search又分filter,query两种模式.filter模式即筛选模式:将符合筛选条件的记录作为结果找出来.query模式则分两个步骤:先 ...
- ES6系列-什么是ES6?新手应该怎么理解
ECMAScript 是什么 很多初学者都很困惑,ECMAScript是什么?它跟JavaScript有什么关系? 大家注意到了吗?从题目中我们就可以看出来了,ECMAScript是JavaScrip ...
- 编程语言千千万,为什么学习Python的占一半?
如果让你从数百种的编程语言中选择一个入门语言?你会选择哪一个? 是应用率最高.长期霸占排行榜的常青藤 Java?是易于上手,难以精通的 C?还是在游戏和工具领域仍占主流地位的 C++?亦或是占据 Wi ...
- thinkphp5 input坑
取值方式改了而已?a1=1&a2=2这种可以用input(get.) a1/1/a2/2 用input('a1')和input('a2') post方法当然是input('post.') 我觉 ...
- JS 获取GET 参数
对于 URL,我们需要了解更多,因为我们的开发中可能会需要提取URL的部分信息来做不同的事情,事实上这也是与后端交互的一种独特的方式,当然这肯定是安全的,当请求被返回,关于 url 的信息就被记录在了 ...
- 关于搭建IIS网页弹出登录框的解决方案
今天自己搭建IIS服务器的时候,明明设置了匿名访问,但是用ie访问127.0.0.1的时候还是会弹出一个登陆框,最后在网上找到答案. 转自: https://blog.csdn.net/sunleib ...