• B. Math Show 暴力 C


    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
    ", 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
    ", ans);
    		}
    	}
    	printf("%lld %lld %lld
    ", x - 1, y - 1, z - 1);
    	return 0;
    }
    

      

  • 相关阅读:
    第一周学习总结
    《淘宝网》质量属性分析
    软件架构师如何工作
    MVC模式
    Python学习
    echarts-数据的视觉映射
    热词展示
    热词关系图
    offset、client、scroll三个系列对比,是否有边框 padding?是否有单位?
    元素滚动 scroll系列属性 如果内容溢出盒子、scroll返回的是内容的大小 是否带边框、单位?
  • 原文地址:https://www.cnblogs.com/EchoZQN/p/11387206.html
Copyright © 2020-2023  润新知