ZOJ Monthly, January 2019 Little Sub and his Geometry Problem ZOJ4082(模拟 乱搞)
在一次被自己秀死...
题目: 给出N,K, Q;
给出一个N*N的矩阵 , 与K个特殊点 , 与Q次查询 , 每次查询给出一个C , 问 在这个N*N矩阵中 , 有多少的点是满足这样的一个关系

问题转换就是说 , 当前的坐标X,Y , 满足一个(X+Y)*cnt - sumxy ; 的关系 , cnt 是指在X,Y这个位置 , 有多少个特殊点会被计算到 , sumXY是满足条件的特殊点的横纵坐标的和 ,;
分析: 经过一些分析后 ,你可以得出一个这样的结论 , 在我查询C 的时候 ,对于放程(X+Y)*cnt - sumxy==C ,随着X的增大 , Y是不断的被减小 , 也就是说 假设我在(X1,Y1 ) 与(X2,Y2) X1<X2是可以满足的 , 那么我们一定是可以得出 Y1<Y2 , 无论X1到X2之间是有多少的特殊点都是如此 , 为什么吗呢? 对于X1 ,X2 如果在X2时满足的特殊点是多的 , 那Y2是不是就一定比Y1要小 ; 所以我们可以依据这样的特性 ,我们枚举一遍(X=1;X<=N ) 这个是当前点的横坐标 ,我同时也枚举Y , 注意 ,因为Y是不会增加的所以 可以把Y看出是指针 , 指向当前X拥有的最大Y;
复制度也就是Q(N+Y+K) Q就10 ,可以过
现在来说说为什么被秀死 , DUG了许久 PE , 说是格式错误,最终找到 ,原来是puts("") 与puts(" ") , 我为了好看习惯性的在里面打了个空格 ,。。。我日..
#include<bits/stdc++.h>
using namespace std ;
#define N 100001
#define ll long long
int n,k;
ll Ysum[N],Ycout[N];
ll ANS[];
struct no
{
int x,y;
}a[N];
bool cmp(no a , no b)
{
if(a.x!=b.x)
return a.x<b.x;
return a.y<b.y;
} ll solve(ll C)
{
memset(Ysum,,sizeof(Ysum));
memset(Ycout,,sizeof(Ycout));
int id=;
ll Y=n;
ll cnt=,sum=; int num=;
for(ll X= ; X<=n ; X++)
{
while(a[id].x<=X && id<=k)
{
if(Y>=a[id].y)
{
cnt++;
sum+=a[id].x+a[id].y;
Ysum[a[id].y]+=a[id].x+a[id].y;
Ycout[a[id].y]++;
}
id++;
}
while((X+Y)*cnt-sum>C)
{
cnt-=Ycout[Y];///有了这些数组我才能知道我CNT , sum应该减去什么
sum-=Ysum[Y];
Y--;
} if((X+Y)*cnt-sum==C)
num++;
}
return num;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
for(int i= ; i<=k ; i++)
{
scanf("%d%d",&a[i].x , &a[i].y);
}
sort(a+,a++k,cmp);
int Q; scanf("%d",&Q);
ll sum=; ll C; for(int i= ; i<=Q ; i++)
{
scanf("%lld",&C);
if(i!=) putchar(' ');
printf("%lld",solve(C));
}
puts("");
}
return ;
}
ZOJ Monthly, January 2019 Little Sub and his Geometry Problem ZOJ4082(模拟 乱搞)的更多相关文章
- ZOJ Monthly, January 2019 Little Sub and his Geometry Problem 【推导 + 双指针】
传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5861 Little Sub and his Geometry Prob ...
- ZOJ Monthly, January 2019
A: Little Sub and Pascal's Triangle Solved. 题意: 求杨辉三角第n行奇数个数 思路: 薛聚聚说找规律,16说Lucas 答案是 $2^p \;\;p 为 n ...
- ZOJ Monthly, January 2019 Little Sub and Isomorphism Sequences 【离线离散化 + set + multiset】
传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5868 Little Sub and Isomorphism Seque ...
- ZOJ Monthly, January 2019 I Little Sub and Isomorphism Sequences(set 妙用) ZOJ4089
写这篇博客来证明自己的愚蠢 ...Orz 飞机 题意:给定你个数组,以及一些单点修改,以及询问,每次询问需要求得,最长的字串长度,它在其他位置存在同构 题解:经过一些奇思妙想后 ,你可以发现问题是传 ...
- ZOJ Monthly, January 2018 训练部分解题报告
A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...
- matrix_2015_1 138 - ZOJ Monthly, January 2015
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3844 第一个,n个数,每次操作最大数和最小数都变成他们的差值,最后n个数相 ...
- ZOJ Monthly, January 2018
A 易知最优的方法是一次只拿一颗,石头数谁多谁赢,一样多后手赢 #include <map> #include <set> #include <ctime> #in ...
- ZOJ Monthly, January 2018 Solution
A - Candy Game 水. #include <bits/stdc++.h> using namespace std; #define N 1010 int t, n; int a ...
- ZOJ Monthly, January 2019-Little Sub and Pascal's Triangle
这个题的话,它每行奇数的个数等于该行行号,如果是0开始的,就该数的二进制中的1的个数,设为k,以它作为次数,2k就是了. #include <stdio.h> int main() { i ...
随机推荐
- 在英文Win7操作系统上部署C#开发的Web系统出现乱码的解决方法
今天,迁移机器,把一个使用C#开发的Web系统部署到一台英文版Win7操作系统上,部署好以后,系统可以登录,只是网页上出现汉字乱码. 在这台电脑上,打开Word等文本编辑器,是可以正常输入.显示中文的 ...
- 使用Cytoscape画PPI网络图
打开Cytoscape软件,根据菜单导入string_interactions.tsv文件 File ----> Import ----> Network from File 会弹出下图对 ...
- dynamic和匿名类和var的混合使用 没提示照样点
using System;using System.Collections;using System.Collections.Generic;using System.Linq;using Syste ...
- 第一章Python简介
1.Python shell(Python命令解释器) 如下所示 2.Python的交互模式 如下 3.代码编辑器窗口 在上面的那些指令称为源代码. 4.在python中,缩进是有语法意义的. 在某行 ...
- Entity Framework Tutorial Basics(41):Multiple Diagrams
Multiple Diagrams in Entity Framework 5.0 Visual Studio 2012 provides a facility to split the design ...
- ArcGIS坐标转换
我忘了怎么设置坐标系了- 定义投影ArcCatalog设置? -arctoolbox好像都可以 感觉不用想的那么复杂]直接定义投影就行了 选这一个吗 这个就行了' 然后? 应该是先定义成 ...
- 编写高质量代码改善C#程序的157个建议——建议61:避免在finally内撰写无效代码
建议61:避免在finally内撰写无效代码 在阐述建议之前,需要先提出一个问题:是否存在一种打破try-finally执行顺序的情况,答案是:不存在(除非应用程序本身因为某些很少出现的特殊情况在tr ...
- 匿名函数和lamda表达式
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- MySql8.0后密码认证方式问题[caching-sha2-password]
这个问题通常在laravel中表现为类似下边的异常: local.ERROR: SQLSTATE[HY000] [2006] MySQL server has gone away {"exc ...
- Linux 内核list_head 学习
Linux 内核list_head 学习(一) http://www.cnblogs.com/zhuyp1015/archive/2012/06/02/2532240.html 在Linux内核中,提 ...