CF611F. New Year and Cleaning

Solution

还挺巧妙的套路。
把起点整体看作一个矩阵,在操作时移出原来矩阵外的部分的起点都是超越边界的,可以直接通过超出的面积计算贡献,再把超出的部分删去,模拟即可(第一轮模拟会与之后有所不同)。

Code

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int llusing namespace std;template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{int f=1,x=0; char c=getchar();while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }return x*f;
}
char st[MAXN];
PR c[MAXN];
int upd(int x,int y) { return x+y>=mods?x+y-mods:x+y; }
void get(int &x,int &y,char ch)
{if (ch=='R') y++;if (ch=='L') y--;if (ch=='D') x--;if (ch=='U') x++;
}
signed main()
{int n=read(),H=read(),W=read(),x2=H,y2=W,x1=1,y1=1,ans=0;scanf("%s",st+1);for (int i=1;i<=n;i++){get(x1,y1,st[i]);get(x2,y2,st[i]);if (x1==0&&x1<=x2&&y1<=y2) x1=1,ans=upd(ans,(y2-y1+1)*i%mods);if (y1==0&&x1<=x2&&y1<=y2) y1=1,ans=upd(ans,(x2-x1+1)*i%mods);if (x2==H+1&&x1<=x2&&y1<=y2) x2=H,ans=upd(ans,(y2-y1+1)*i%mods);if (y2==W+1&&x1<=x2&&y1<=y2) y2=W,ans=upd(ans,(x2-x1+1)*i%mods);}int num=0;for (int i=1;i<=n;i++){get(x1,y1,st[i]);get(x2,y2,st[i]);if (x1==0&&x1<=x2&&y1<=y2) x1=1,ans=upd(ans,(y2-y1+1)*(i+n)%mods),c[++num]=MP(i,0);if (y1==0&&x1<=x2&&y1<=y2) y1=1,ans=upd(ans,(x2-x1+1)*(i+n)%mods),c[++num]=MP(i,1);if (x2==H+1&&x1<=x2&&y1<=y2) x2=H,ans=upd(ans,(y2-y1+1)*(i+n)%mods),c[++num]=MP(i,0);if (y2==W+1&&x1<=x2&&y1<=y2) y2=W,ans=upd(ans,(x2-x1+1)*(i+n)%mods),c[++num]=MP(i,1);}if (!num&&x1<=x2&&y1<=y2) { puts("-1"); return 0; }for (int nw=2,x=x2-x1+1,y=y2-y1+1;x>0&&y>0;nw++)for (int i=1;i<=num;i++) {if (c[i].se==0&&x>0&&y>0) ans=upd(ans,max(y,0ll)*(nw*n%mods+c[i].fi)%mods),x--;if (c[i].se==1&&x>0&&y>0) ans=upd(ans,max(x,0ll)*(nw*n%mods+c[i].fi)%mods),y--;}printf("%lld\n",ans);return 0;
}

CF611F. New Year and Cleaning相关推荐

  1. 【BZOJ】1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(dp/线段树)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1672 dp很好想,但是是n^2的..但是可以水过..(5s啊..) 按左端点排序后 f[i]表示取第 ...

  2. 动态规划 BZOJ1584 [Usaco2009 Mar] Cleaning Up 打扫卫生

    1584: [Usaco2009 Mar]Cleaning Up 打扫卫生 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 511  Solved: 3 ...

  3. cleaning selected projects has encountered a problem errors occurred during build

    clean 项目的时候出现的问题. cleaning selected projects has encountered a problem errors occurred during build ...

  4. Linux mount: Structure needs cleaning 错误解决方法

    "mount: Structure needs cleaning"报错 可以使用xfs_repair来修复,但是要注意 xfs_repair修复的分区中的文件都会丢失,即使是du能 ...

  5. CF1245F Daniel and Spring Cleaning(等会了更新)

    CF1245F Daniel and Spring Cleaning 题意: 给定l,r,求∑a=lr∑b=lr[a+b=a⊕b]\sum_{a=l}^{r}\sum_{b=l}^{r}[a+b=a⊕ ...

  6. 【POJ - 2376】Cleaning Shifts (贪心)

    题干: Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores ...

  7. poj 2376 bzoj 3389: [Usaco2004 Dec]Cleaning Shifts安排值班(贪心)

    3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 462  Solved ...

  8. bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(DP)

    1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 941  Solved ...

  9. 【安卓学习之常见问题】 使用Eclipse clean时,出现“cleaning all project has encountered a problem”提示

    在使用Eclipse时,经常需要clean下工程,结果每次clean都提示:"cleaning all project has encountered a problem. Errors o ...

最新文章

  1. python windows epoll_Windows 10生产力提升之WSL实践
  2. 深度学习也利用进化论!李飞飞谈创建具身智能体,学动物进化法则
  3. How does Spring @Transactional Really Work?--转
  4. CMake入门(二)
  5. 一些Web Service的经验
  6. 官司缠身!马斯克和特斯拉目前面临数十起诉讼和调查
  7. Adobe 全家桶关闭自动更新?技巧来啦!
  8. 06. 当心C++编译器最烦人的分析机制
  9. JS 中样式显示(clientWidth和clientHeight、offsetLeft、scrollHeight )
  10. 树莓派3降低内核版本,安装Tenda U6 RTL8192无线网卡驱动
  11. 第三章 硅谷宠儿 Friendster (二)
  12. 倒立摆系统的多种控制器设计
  13. 晓得不,中间表是这样被消灭的
  14. “马赛克”真能去除了?老司机狂喜!这一神器一键去除!
  15. 河北科技师范学院对口计算机分数线,河北科技师范学院对口分数线
  16. PROC REPORT过程
  17. 浅谈面向对象和面向过程
  18. 合振动的初相位推导_②音响处理器肿么调?处理器教学 音箱延时相位耦合就是这么简单【愤怒的调音师】...
  19. php实现仿淘票票订票网站
  20. 利用自主电源管理器简化锂离子电池充电过程

热门文章

  1. 2个网页跳来跳去_好人网页同步器,使用教程
  2. 纸盒叠成的长方形竟然能自己动?
  3. 中国的这些民居都是你没见过的!
  4. 有朋友问我为什么这么帅
  5. 天赋差的程序员,难道就只能半途而废吗?
  6. 这是一份编程宝典,请查收!
  7. html、css、js注释,js,html,css注释大集合
  8. hashset默认长度是多少?_看看,这些细节上的坑,你犯了多少?
  9. java获取jtable的路径,Java如何在JTable组件中获取选定的单元格?
  10. python求解微分方程组_python – SymPy / SciPy:求解具有不同变量的常微分方程组...