思路:模拟题,留意到其实左右操作是会抵消的,所以只用考虑上下就好了

#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
#define LL long long
vector<vector<int> >mp;
char *str = "UDLR";
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int main()
{int T,cas=1;scanf("%d",&T);while(T--){int n,m,k;scanf("%d%d%d",&n,&m,&k);int r = 1,c=1;mp = vector<vector<int> >(n+5,vector<int>(m+5));for (int i = 0;i<k;i++){char op;int s;scanf(" %c%d",&op,&s);if (op=='U'){mp[r-s][c]-=1;mp[r][c]+=1;}if (op=='D'){mp[r][c]+=1;mp[r+s][c]-=1;}int d = strchr(str,op)-str;r+=s*dir[d][0];c+=s*dir[d][1];}LL ans =0;for(int i = 1;i<=n;i++){for (int j = 1;j<=m;j++){mp[i][j]+=mp[i-1][j]+mp[i][j-1]-mp[i-1][j-1];ans+=mp[i][j]*mp[i][j];}}printf("Case #%d: %lld\n",cas++,ans);}
}

You have a rectangle of size N × M, N rows from top to bottom and M columns from left to right,
that is divided into a grid of unit squares. The corners and sides of those squares will be called grid
points and grid lines, respectively.
You are given a path along some grid lines. The path satisfies the following properties:
• Both start and end of the path are at the top left grid point.
• Each step is to go along the grid line (i.e., move up, down, left, or right).
You need to calculate the square sum of all the rotation values in each all. The definition of the
notation value in each cell is below.
Suppose there is a moving car at the path and a person stands at the center of the cell. The person
is facing the car all the time. After the path is finished, the rotation value of the grid equals to the
net number of clockwise turns the person would make if he stood in that square. (In other words, if
the person standing in that square rotate by the same total amount clockwise and counterclockwise,
the rotation value is 0. If the person’s total clockwise rotation is 360x degrees more than the person’s
total counterclockwise rotation, the rotation value of the cell is x. If the person’s total couuterclockwise
rotation is 360x degrees more than the person’s total clockwise rotation, the rotation value of the cell
is −x)
Input
The first line of the input gives the number of test cases, T. T cases follow. For each test case, the first
line contains three numbers, N, M and K. The next K line describes the steps of the path. Each line
containing ‘d s’, where d is one of the four characters (‘U’ for up, ‘D’ for down, ‘L’ for left, ‘R’ for right)
means the direction of the step and s is the length of the step.
It is guaranteed that the path is inside the grid.
Output
For each test case, output one line containing ‘Case #x: y’, where x is the test case number (starting
from 1) and y is square sum of all the rotation values of each cell.
Limits:
1 ≤ T ≤ 100
1 ≤ N, M
1 ≤ N × M ≤ 106
1 ≤ K ≤ 104
The path is valid.
Sample Input
4
1 1 4
R 1
D 1
L 1
U 1
1 1 4
D 1
R 1
U 1
L 1
2 2 6
R 1
D 2
R 1
U 1
L 2
U 1
2 2 8
R 1
D 1

R 1
D 1
L 1
U 1
L 1
U 1
Sample Output
Case #1: 1
Case #2: 1
Case #3: 2
Case #4: 2

UVALive 7139 Rotation(模拟)相关推荐

  1. UVALive - 7139 Rotation 矩阵前缀和(imos和)

    传送门:UVALive 7139 题意:N*M的网格,一辆车沿着网格线按给定路线走,每个网格里有一个人,人的视线始终看着车,问这些人净转圈数的平方和. 思路:因为起点和终点都是左上角,因此我们可以维护 ...

  2. UVALive 7139 Rotation(矩阵前缀和)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  3. UVALive 7139 Rotation

     这个题就是模拟题,但是性质很深. 观察可得到一个结论:对于一个方格中的人来说,如果要有一个完整的时针旋转,则必然是一边走下去,一边走上去,且"包含"所以不用考虑R,L. 若车 ...

  4. UVALive 7139 - Rotation

    传送门 题意:由n*m个格子组成的网格地图,一辆车沿着边移动,车从起点出发,最终又回到起点 每个格子中间都站着一个人,一直面向着车,若(x,y)格子的人在车子行驶过程中,顺时针转了a度,逆时针b度,则 ...

  5. UVALive 7139 Rotation 二维vector+矩阵前缀和 【模版】

    题目大意:给一个n*m的矩阵,每个方块上有一个人.现在有一辆车在左上角的格点处,矩阵里的人都会一直面向那辆车.现在给出车的移动路线,问每个人总旋转角度的平方和是多少.若一个人顺时针旋转10个圈,逆时针 ...

  6. UVALive - 7139(差分+模拟)

    题目链接 参考 题意 N*M的网格,一辆车沿着网格线按给定路线走,每个网格里有一个人,人的视线始终看着车,问这些人净转圈数的平方和. 分析 由于车的起点和终点都为左上角,且每个格子里的人永远面对着车, ...

  7. UVALive - 6440(模拟)

    题目链接:https://vjudge.net/contest/241341#problem/G 题目大意:输入一个N,n次操作.对于第一种操作增加一个病人,告诉病人的t0,st0,r.第二种操作,在 ...

  8. HDU 4708 Rotation Lock Puzzle(模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 题目大意:给定一个方形矩阵,边长为3-10的奇数.每一圈的数字可以沿着顺时针方向和逆时针方向旋转 ...

  9. UVALive 6093 Emergency Room --优先队列实现的模拟

    题意:给n个医生,这些医生有一个上班时间,然后给一些病人,病人有一个到达的时间,以及一些诊断,诊断有property(优先级)和duration(诊断时间)这两个属性,每个病人可能要诊断多次,最后问每 ...

最新文章

  1. LVS_NAT实现负载均衡
  2. 前端如何实现:在不刷新页面的情况下实时看到自己的评论
  3. 怎么从运营转到前端开发_我如何在16个月内从销售人员转到前端开发人员
  4. 谈自动化测试与CI中一些常见的谬见
  5. js开源框架最新版下载
  6. D. Bash and a Tough Math Puzzle(区间gcd+思维)
  7. zbbz的lisp_学习LISP语言的体会
  8. 国产管理软件勒索病毒大爆发
  9. 关于电商平台推出无门槛优惠券不得不说的几个问题
  10. 百度搜索下拉框及百度相关搜索中刷关键字方法
  11. python中的in和out是什么意思
  12. Blender游戏开发教程
  13. SystemUI添加第三方快捷开关时灰显问题分析
  14. 毕业设计:基于java的小区物业信息管理系统的设计与实现(1)
  15. 干货 | 95后运维小哥20天+通过Elastic认证考试经验分享
  16. 使用latex画好看的深度学习模型图(基于Windows平台)
  17. 【ICLR 2023】RankCSE:基于排序学习的无监督句子表示学习
  18. Linux: 查看文件和文件夹大小的df和du命令
  19. java上机实验报告(7)_Java上机实验报告
  20. c#语言怎么定义函数,C#方法方法用法 _C#语言-w3school教程

热门文章

  1. 宝宝的成长脚印8/17
  2. 数学工具MapleSim2022的安装配置使用
  3. SC0096—AT32F403A/407 MSC IAP SpiFlash As Disk
  4. 一阶差分与二阶差分及还原
  5. 马航发布会确认MH370失事:这是史无前例的悲剧
  6. html作业 百度网盘,百度学院任务一:零基础HTML编码 作业.html
  7. 再见了Origin,这才是科研法宝,新手秒出图!
  8. GIF动态图怎么提取成图片?分享三个动态图提取成图片的方法
  9. 如何在Excel/WPS表格中批量查询快递信息?
  10. kaldi学习 - egs/yesno —— 数据准备(一)