B. Math Show

这个题目直接暴力,还是有点难想,我没有想出来,有点思维。

#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;
}

  

C. Four Segments

这个题目我觉得还是有点难,这个题目求 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;
}

  

最新文章

  1. [PCL]点云渐进形态学滤波
  2. JVM学习笔记:虚拟机的类加载机制
  3. 《Java中的包机制》
  4. 最短路(Bellman_Ford) POJ 3259 Wormholes
  5. easyui tab 关闭
  6. ggplot2 demo
  7. 隐藏NGINX服务器名称 和版本号
  8. 如何使用wait(), notify() and notifyAll() – Java
  9. BZOJ 1072: [SCOI2007]排列perm [DP 状压 排列组合]
  10. UVa-156 Ananagrams(map映射)
  11. java线程和多线程同步
  12. Python 两个星号(**)的 参数
  13. CCF-URL映射-(正则匹配)-20180303
  14. CentOS75 安装Oracle18c
  15. Linux &#39;XXXXXX&#39; &quot;is not in the sudoers file. This incident will be reported&quot; 解决方法
  16. 嵌入式Linux软件工程师面试题一
  17. ELK基础学习
  18. Python 正则:前后界定和前后非界定
  19. leetcode 之Search in Rotated Sorted Array(三)
  20. 在父页面和其iframe之间函数回调 父页面回调iframe里写的函数

热门文章

  1. http的请求头都有那些信息
  2. Node.js 的事件循环机制
  3. I/O流之--转换流:InputStreamReader 和InputStreamWriter
  4. 做一个通过dockerfile从零构建centos7.4
  5. 编写高质量Python程序(四)库
  6. ORA-0245
  7. Linux protobuf
  8. 常见web漏洞的整理之SQL注入
  9. [PHP] 获取IP 和JS获取IP和地址
  10. curl book