在一次被自己秀死...

飞机

题目: 给出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(模拟 乱搞)的更多相关文章

  1. 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 ...

  2. ZOJ Monthly, January 2019

    A: Little Sub and Pascal's Triangle Solved. 题意: 求杨辉三角第n行奇数个数 思路: 薛聚聚说找规律,16说Lucas 答案是 $2^p \;\;p 为 n ...

  3. 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 ...

  4. ZOJ Monthly, January 2019 I Little Sub and Isomorphism Sequences(set 妙用) ZOJ4089

    写这篇博客来证明自己的愚蠢 ...Orz  飞机 题意:给定你个数组,以及一些单点修改,以及询问,每次询问需要求得,最长的字串长度,它在其他位置存在同构 题解:经过一些奇思妙想后 ,你可以发现问题是传 ...

  5. ZOJ Monthly, January 2018 训练部分解题报告

    A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...

  6. matrix_2015_1 138 - ZOJ Monthly, January 2015

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3844 第一个,n个数,每次操作最大数和最小数都变成他们的差值,最后n个数相 ...

  7. ZOJ Monthly, January 2018

    A 易知最优的方法是一次只拿一颗,石头数谁多谁赢,一样多后手赢 #include <map> #include <set> #include <ctime> #in ...

  8. ZOJ Monthly, January 2018 Solution

    A - Candy Game 水. #include <bits/stdc++.h> using namespace std; #define N 1010 int t, n; int a ...

  9. ZOJ Monthly, January 2019-Little Sub and Pascal's Triangle

    这个题的话,它每行奇数的个数等于该行行号,如果是0开始的,就该数的二进制中的1的个数,设为k,以它作为次数,2k就是了. #include <stdio.h> int main() { i ...

随机推荐

  1. 网页开发中调用iframe中的函数或者是dom元素

    iframe中的代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <hea ...

  2. 680. Valid Palindrome II 对称字符串-可删字母版本

    [抄题]: Given a non-empty string s, you may delete at most one character. Judge whether you can make i ...

  3. 551. Student Attendance Record I 从字符串判断学生考勤

    [抄题]: You are given a string representing an attendance record for a student. The record only contai ...

  4. POI技术

    1.excel左上角有绿色小图标说明单元格格式不匹配 2.模板中设置自动计算没效果,需要加上sheet.setForceFormulaRecalculation(true); FileInputStr ...

  5. fopencookie函数详解

    今天看DPDK时,看到了fopencookie函数,以前基本没有用过该函数,乘此机会好好看看如何使用. 1. 函数头文件与函数原型 函数头文件: #include <stdio.h> 函数 ...

  6. ROS indigo Ubuntu14.04 安装问题

    错误信息:Unpacking ros-indigo-desktop-full (1.1.6-0trusty-20181006-135515-0800) ... Errors were encounte ...

  7. oracle高级查询练习题

    1.  列出员工表中每个部门的员工数和部门编号 Select deptno,count(*) from emp group by deptno; 补充1:列出员工表中,员工人数大于3的部门编号和员工人 ...

  8. pandas map, apply, applymap区别

    map只对一个序列而言的. apply只是整个dataframe上任意一列或多列,或者一行或多行, 即可在任意轴操作. 在一列使用apply时,跟map效果一样. 多列时只能用apply. apply ...

  9. Linux、Windows中的相对路径和绝对路径

    获取系统的分隔符的方式:System.getProperty("file.separator")   Windows为 \   Linux为/ Windows绝对路径: 以盘符开始 ...

  10. getchar() getch() getche() gets() puts() scanf()的用法及区别

    getchar() putchar(ch) scanf()   头文件stdio.h getch() getche()   头文件conio.h gets() puts()    头文件stdio.h ...