这道题的构造法真的复杂……要推一堆公式……这道题写了几天了……还是没写出来……

一开始简单的觉得先左右来回, 然后上下来回, 然后把剩下的执行完了好了, 然后就WA。

然后换了个思路, 觉得是贪心, 觉得只要保证当前留下的最多就ok了, 然后又WA。

这里不能每一步贪心, 因为当前最优不能保证以后是最优的。

然后找数据发现, 其实当留下的个数一样多的时候还要有格外的优先级,而且分很多种情况。

然后就去看了很多博客。

发现原来开始还要先判断往南北还是东西, 然后东西完了之后再每次判断南北还是西, 然后再判断

剩下的。想的这么周全也是人才。

#include<cstdio>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
typedef long long ll; ll solve(ll x, ll y, ll n, ll s, ll w, ll e)
{
ll res = 0;
if(s > n) swap(s, n);
if(e > w) swap(e, w); if(n) //东西来回
{
res += x * y;
x--; n -= s;
if(n) res += x * y * s * 2, n--;
else res += x * y * (s * 2 - 1);
s = 0;
} if(w) //判断向南北还是向西
{
w -= e;
if(w) e *= 2, w--;
else e = e * 2 - 1;
while((1 - y) * e >= y - x && n) //两串很长的公式最后的化简结果
{
res += x * y;
n--; x--;
}
res += x * y; y--;
res += x * y * e; e = 0;
} while(x * y > 0 && n + w > 0) //剩下的处理掉
{
res += x * y;
if((x > y && n) || !w) n--, x--;
else w--, y--;
} return res;
} int main()
{
int kase = 0;
ll x, y, n, s, w, e; //要开long long
while(~scanf("%lld%lld", &x, &y) && x && y)
{
scanf("%lld%lld%lld%lld", &n, &s, &w, &e);
ll res = max(solve(x, y, n, s, w, e), solve(y, x, e, w, n, s)); //两种情况都做一遍取最大
printf("Case %d: %lld\n", ++kase, res);
}
return 0;
}

最新文章

  1. steps animation
  2. Laravel 5如何在中间件中获取路由参数?
  3. 在ECSHOP后台左侧导航中增加新菜单
  4. [转载] nginx的负载均衡
  5. lesson10:hashmap变慢原因分析
  6. centos U盘安装
  7. 【译】JavaScript 开发者年度调查报告
  8. 【问题解决】syntax error: unexpected end of file或-bash: ./full_build.sh: /bin/bash^M: bad interpreter: No
  9. 微信小程序学习总结(1)
  10. 深度学习系列 Part (1)
  11. Map、Set、List 集合 差别 联系
  12. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)
  13. JS中文档碎片的理解和使用
  14. 【CS231N】7、卷积神经网络
  15. js自定义鼠标右键菜单
  16. 虚拟化安全 sandbox 技术分析
  17. 使用javascript开发的视差滚动效果的云彩
  18. Servlet------&gt;jsp自定义标签2(让标签体不显示)
  19. Hadoop的简单序列化框架
  20. enq:TM-contention

热门文章

  1. 8、Situation-Dependent Combination of Long-Term and Session-Based Preferences in Group Recommendations: An Experimental Analysis ----组推荐中基于长期和会话偏好的情景依赖组合
  2. 说说Shell在代码重构中的应用
  3. Vue学习之路第八篇:事件修饰符
  4. 在join中,on和where的区别
  5. oracle用户锁定
  6. 20个C#热点问题
  7. 【IPC进程间通讯之三】内存映射文件Mapping File
  8. BEGINNING SHAREPOINT&amp;#174; 2013 DEVELOPMENT 第6章节--在SharePoint2013中开发、集成和构建应用程序 总结
  9. NHibernate3剖析:Query篇之NHibernate.Linq增强查询
  10. java中的输入输出&lt;1&gt;