G - Best ACMer Solves the Hardest Problem Gym - 101955G
G - Best ACMer Solves the Hardest Problem Gym - 101955G
题意:
我们需要建立一个数据库以支持实时查询和修改。这个数据库中的记录是点坐标 (x,y) 和其权值 w。查询与修改操作可以表示为
1 x y w,在 (x,y) 处插入一个新的点,我们保证在插入之前该位置没有点。
2 x y,删除 (x,y) 处的点,我们保证在删除之前该位置存在一点。
3 x y k w,对于每一个到 (x,y) 的欧几里得距离为 sqrt(k) 的点,给它的权值增加 w。
4 x y k,对于每一个到 (x,y) 的欧几里得距离为 sqrt(k) 的点,求出它们权值 w 的和。
其中 (x0,y0) 与 (x1,y1) 的欧几里得距离为 sqrt((x0 - x1)2 + (y0 - y1)2)
为了让所有 x 和 y 动态,我们引入变量 lastans 来表示上一次查询的结果,其初始值为 0。对于每一个操作中的 x 和 y,它们的真实值分别为 (x+lastans)%6000+1 和 (y+lastans)%6000+1
0 ≤ k ≤ 107, 1 ≤ x, y, w ≤ 6000
题解:
如果对于每次查询,我们先搜与该点欧几里得距离为len的点,肯定不行,我们可以预处理,先算出与原点距离在1e7以内的所有点,并用相应的距离存储,当之后要对(x,y)查询时,我们可以直接调用过来
比如(x1,y1)距离原点为k,说明(x1)2+(y1)2=k,那么(x-(t * x1+x))2+(y-(t * y1+y))2=k
t可以是-1或者1,其实也就是x和y分别向四个方向伸的点
代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;const int maxv=1e7+10;
const int maxn=6006;
int n,m;
typedef pair<int,int> pp;
vector<pp >v[maxv],cc;
int mp[maxn][maxn];
ll lastans;
int poww[maxv];
set<pair<int,int> >cnt;
set<pair<int,int> >::iterator it;
int dir[4][2]={{1,1},{1,-1},{-1,1},{-1,-1}};void init()
{for(int i=0;i<=6000;i++){for(int j=0;j<=6000;j++){if(i*i+j*j<=1e7){v[i*i+j*j].push_back(make_pair(i,j));}elsecontinue;}}
}int judge(int x,int y)
{if(x<=0||y<=0||x>6000||y>6000)return 0;return 1;
}int main()
{init();int t;scanf("%d",&t);for(int cas=1;cas<=t;cas++){cc.clear();printf("Case #%d:\n",cas);lastans=0;scanf("%d %d",&n,&m);for(int i=1;i<=n;i++){int x,y,w;scanf("%d %d %d",&x,&y,&w);mp[x][y]=w;cc.push_back(make_pair(x,y));}for(int qq=1;qq<=m;qq++){int op,x,y,w,k;scanf("%d",&op);if(op==1){scanf("%d %d %d",&x,&y,&w);x=(x+lastans)%6000+1;y=(y+lastans)%6000+1;mp[x][y]=w;cc.push_back(make_pair(x,y));}else if(op==2){scanf("%d %d",&x,&y);x=(x+lastans)%6000+1;y=(y+lastans)%6000+1;mp[x][y]=0;}else if(op==3){scanf("%d %d %d %d",&x,&y,&k,&w);x=(x+lastans)%6000+1;y=(y+lastans)%6000+1;cnt.clear();for(int i=0;i<v[k].size();i++)//查询距离为k的点 {int xx=v[k][i].first;int yy=v[k][i].second;for(int j=0;j<=3;j++){int nx=xx*dir[j][0]+x;int ny=yy*dir[j][1]+y;if(judge(nx,ny)&&mp[nx][ny]!=0){cnt.insert(make_pair(nx,ny));}}}for(set<pp>::iterator it=cnt.begin();it!=cnt.end();it++){mp[it->first][it->second]+=w;}}else{scanf("%d %d %d",&x,&y,&k);x=(x+lastans)%6000+1;y=(y+lastans)%6000+1;cnt.clear();for(int i=0;i<v[k].size();i++){int xx=v[k][i].first;int yy=v[k][i].second;for(int j=0;j<=3;j++){int nx=xx*dir[j][0]+x;int ny=yy*dir[j][1]+y;if(judge(nx,ny)&&mp[nx][ny]!=-1){cnt.insert(make_pair(nx,ny));}}}ll ans=0;for(set<pp>::iterator it=cnt.begin();it!=cnt.end();it++){ans+=mp[it->first][it->second];}lastans=ans;printf("%lld\n",ans);}}for(int i=0;i<cc.size();i++){mp[cc[i].first][cc[i].second]=0;}}return 0;
}
G - Best ACMer Solves the Hardest Problem Gym - 101955G相关推荐
- HDU1048 The Hardest Problem Ever
问题链接:HDU1048 The Hardest Problem Ever.入门训练题,用C语言编写程序. 以往,密码通信是一件重要的事情,是一项高技术的工作.不过译码的时候,通常是通过查密码本来实现 ...
- Mediocre String Problem Gym - 101981M
https://cn.vjudge.net/problem/Gym-101981M 很容易tle #include <iostream> #include <cstring> ...
- poj 1298 The Hardest Problem Ever
题目链接:http://poj.org/problem?id=1298 题目大意:按照所给的顺序要求将输入的字符串进行排列. 1 #include <iostream> 2 #includ ...
- HDU 1048 The Hardest Problem Ever
原题大意: 给出相应的密码本,将密文字母按照所给密码本列出的对应关系解密,字母均为大写,对于非大写字母则同密文保持一致,即不用翻译原样输出. 密码本:Cipher text(密文)A B C D E ...
- AtCoder Beginner Contest 281 (A-F,口胡G)青大acmer 日常vp
A - Count Down 输出小于等于nnn的数 代码 B - Sandwich Number 题意 问字符串是否是第一个和最后一个字符是大小写,中间的字符是100000−99999100000- ...
- HDU 1048 [The Hardest Problem Ever] 字符串处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1048 题目大意:对一串字符串进行加密:每个英文字母变为字母表此后第五位,其他字符无变化.给出密码,要求 ...
- M - Mediocre String Problem Gym - 101981M
题意: 给你个s串和t串 找三元组(i,j,k) 在 s中选取 i -j ,在t中选取 1-k,使他们拼凑出来的是回文串. 题解:首先对于s串倒转,exkmp求s串和t串extend,对s串进行ma ...
- 2018-2019 ACM-ICPC, Asia Shenyang Regional Contest题解
以下所有AC题解代码来自"仙客传奇"团队. AC题数:4/13 CGJK A. Sockpuppets B. Sequences Generator C. Insertion So ...
- 2018沈阳oniste J-C-G-E题
目录 J. How Much Memory Your Code Is Using? 题目链接\href{https://nanti.jisuanke.com/t/A2171}{题目链接}题目链接 题意 ...
最新文章
- Spring Boot 集成 Activiti
- vue 倒序遍历数组_【一天一大 lee】从中序与后序遍历序列构造二叉树 (难度:中等)Day20200925...
- ora-12514报错解决方法
- 博客园程序源代码下载
- Java lamda表达式快速分组
- 现代软件工程 第六章 【敏捷流程】练习与讨论
- PAT编程:A除以B (20)——C语言
- oracle异构迁移,异构数据库系统迁移到Oracle 工具 - Oracle SQL Developer
- 小程序入门学习03--navigator组件
- java商城项目_javaweb实战之商城项目开发(一)
- 只允许选中三级选择框的方法
- (转载)web.xml中 IntrospectorCleanupListener的作用
- 原生JS实现HTML文件上传,简单实现js上传文件功能
- 批量合成bilibili的m4s缓存文件为MP4格式
- 时代》杂志评出的100部最佳英语小说(含下载)
- 【Python机器学习基础教程】(三)
- 求每个月的最后一天日期
- Final Cut Pro V10.6.5 MAC 专属视频后期工具
- 国内地理信息系统公司及招聘岗位要求
- 列举IE与其他浏览器不一样的特性?