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 ...
随机推荐
- Odoo 查看 模块app 对应的 源码 相关依赖模块信息
安装好app后再路径上 加上debug ,在查看 app 信息 如下 http://127.0.0.1:8069/web?debug#id=138&view_type=form&mod ...
- JavaScript实现简单的弹幕效果实例分析
不知大家有没有感受到,弹幕又是另一出好戏!! 不过我个人还是比较排斥看电视的时候被出来的弹幕打扰.今天我们来写一个简单的弹幕.简单到什么程度呢?看下效果: 由图可以看出,我们的呆毛html结构确实是非 ...
- C. Beautiful Regional Contest
用前缀和写一直wa.. 思路:让金牌和银牌最少,通多增加铜牌的方式来扩大总奖牌的个数. #include<bits/stdc++.h> using namespace std; map&l ...
- Cucumber(3)——命令以及日志
目录 回顾 基本执行命令 关于日志的生成 回顾 在上一节中,我介绍了cucumber一些基本的语法内容,如果你还没有进行相关的了解或者环境的配置,你可以点击这里来进行了解一下 在本节中,我会对cucu ...
- [Php][linux][nginx] 安装总结
就想总结一份安装环境文档,因为文档很多问题也很多,总结一份自己的安装文档! 首先,环境CentOS7,linux环境,windows! 1. 网络配置! vi /etc/sysconfig/netwo ...
- Java面试系列第一篇-基本类型与引用类型
这篇文章总结一下我认为面试中最应该掌握的关于基本类型和引用类型的面试题目. 面试题目1:值传递与引用传递 对于没有接触过C++这类有引用传递的Java程序员来说,很容易误将引用类型的参数传递理解为引用 ...
- 【FishFX】花式撩骚,打造TypeScript易用框架。
· 栗子入手 假设有以下foo数组,数组中每个对象都拥有id,name两个属性,现在需要查找id > 0的对象数量. const foo: Array<{ id: number, name ...
- 关于Sysinternals Suite
sysinternals 的网站创立于1996年由Mark russinovich和布赖科格斯韦尔主办其先进的系统工具和技术资料·微软于2006年7月收购sysinternals公司 . 不管你是一个 ...
- 《HelloGitHub》第 49 期
兴趣是最好的老师,HelloGitHub 就是帮你找到兴趣! 简介 分享 GitHub 上有趣.入门级的开源项目. 这是一个面向编程新手.热爱编程.对开源社区感兴趣 人群的月刊,月刊的内容包括:各种编 ...
- python学习笔记(三)---字典
字典 在Python中,字典 字典 是一系列键 键-值对 值对 .每个键 键 都与一个值相关联,你可以使用键来访问与之相关联的值.与键相关联的值可以是数字.字符串.列表乃至字典.事实上,可将 任何Py ...