XidianOJ 1177 Counting Stars
题目描述
"But baby, I've been, I've been praying hard,
Said, no more counting dollars
We'll be counting stars"
Grandpa Shaw loves counting stars.
One evening he was sitting in his armchar, trying to figure out this problem.
Consider the sky as a rectangular coordinates, each star has a coordinate (Xi,Yi).
To make it simple, all the stars are in the first quadrant.
Now he want to know how many stars there are in the square formed by (0,0) and (x,y).
(including stars in edges, 4 vertices of the square is (0,0) (x,0) (x,y) (0,y))
There are n stars in the sky, and he raised m questions.
Because grandpa Shaw's eyesight is poor, he ask you for help.

in this image, yellow stars are in the square, blue ones are not.
输入
multiple test cases, please read until EOF.
for each test case:
first line contains two integers n m (0 <= n, m <= 10^5).
following n lines each line contains two integers Xi Yi (0 <= Xi, Yi <= 10^6).
following m lines each line contains two integers x y (0 <= x, y <= 10^6).
输出
for each test case:
first line "Case #t:" t is the number of test case.
following m lines, each line contains one integer, the number of stars in that square.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int n,m;
int c[],ans[]; struct StarNode {
int x,y;
int num;
bool query;
};
struct StarNode star[]; bool cmp(struct StarNode s1,struct StarNode s2){
if (s1.x == s2.x) return s1.y < s2.y;
return s1.x < s2.x;
}
int lowbit(int i) {
return i&-i;
}
void Update(int i,int x){
while (i < ){
c[i] += x;
i += lowbit(i);
}
}
int Sum(int i){
int s = ;
while (i > ) {
s += c[i];
i -= lowbit(i);
}
return s;
} int main(){
int total = ;
while (scanf("%d %d",&n,&m) != EOF){
memset(c,,sizeof(c)); total ++;
int i,j;
for (i=;i<=n;i++){
int xi,yi;
scanf("%d %d",&star[i].x,&star[i].y);
star[i].query = false;
}
for (i=n+;i<=n+m;i++){
scanf("%d %d",&star[i].x,&star[i].y);
star[i].query = true; star[i].num = i - n;
}
sort(star+,star++n+m,cmp);
printf("Case #%d:\n",total);
for (i=;i<=n+m;i++){
if (star[i].query)
ans[star[i].num] = Sum(star[i].y+);
else
Update(star[i].y+,);
}
for (i=;i<=m;i++)
printf("%d\n",ans[i]);
}
return ;
}
XidianOJ 1177 Counting Stars的更多相关文章
- Counting Stars
Counting Stars 题目链接:http://acm.xidian.edu.cn/problem.php?id=1177 离线+一维树状数组 一眼扫过去:平面区间求和,1e6的数据范围,这要h ...
- HDU 6184 Counting Stars
Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful!S ...
- 【刷题】HDU 6184 Counting Stars
Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful! ...
- [hdu 6184 Counting Stars(三元环计数)
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...
- HDU 6184 Counting Stars 经典三元环计数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6184 题意: n个点m条边的无向图,问有多少个A-structure 其中A-structure满足V ...
- HDU6184【Counting Stars】(三元环计数)
题面 传送门 给出一张无向图,求 \(4\) 个点构成两个有公共边的三元环的方案数. 题解 orz余奶奶,orz zzk 首先,如果我们知道经过每条边的三元环个数\(cnt_i\),那么答案就是\(\ ...
- hdu6184 Counting Stars 【三元环计数】
题目链接 hdu6184 题解 题意是让我们找出所有的这样的图形: 我们只需要求出每条边分别在多少个三元环中,记为\(x\),再然后以该点为中心的图形数就是\({x \choose 2}\) 所以我们 ...
- 全国高校网安联赛Web专场~WriteUp
1.Sign 题目:Good Luck!flag{X-nuca@GoodLuck!} Flag直接写在题目上了,flag{X-nuca@GoodLuck!} 2.BaseCoding 提示:这是编码不 ...
- Python 新浪微博中提取最常见转载的微博转载了几次,username,内容
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-4 @author: guaguastd @name: fi ...
随机推荐
- Unity UGUI RectTransform图解
UGUI RectTransform.Unity RectTransform详解 The first:look look API. http://docs.unity3d.com/ScriptRefe ...
- 委托Delegate,多播委托和委托链
定义一个委托 public delegate void CalculateDelegate(int 32 x,int 32 y); 定义一个委托类型的变量 public static Calculat ...
- [20150522]RPM包的管理
RPM包的管理 RPM包的分类 RPM包可分为源码包和二进制包两类.源码包的主要优点是开源,如果有足够的能力,可以修改源代码,源码包可以自由选择所需要安装的功能,软件是编译安装,所以更加适合自己的系统 ...
- 自定义滚动条样式(jQuery插件、Webkit、IE)
-------------jQuery滚动条插件------------- http://manos.malihu.gr/tuts/jquery_custom_scrollbar.html http: ...
- win7 下 arp 绑定mac和Ip
我们都知道直接执行arp -s 命令即可绑定IP和MAC地址,但是在Win7下会遇到不能运行arp -s 进行静态mac绑定的情况,提示“ARP 项添加失败: 拒绝访问.”(英文版提示:The ARP ...
- JAVA 对象引用,以及对象赋值
注:引自http://zwmf.iteye.com/blog/1738574 关键字: java对象 引用 Java对象及其引用 关于对象与引用之间的一些基本概念. 初学Java时,在很长一段时间里, ...
- 通过前台选择输入用来计算圆,三角形以及长方形的面积(此题目主要是while以及if 的使用)
#!/bin/usr/env python#coding=utf-8'''完成一段简单的Python程序,用于实现计算圆面积,三角形面积,长方形面积'''flag=Truewhile flag: pi ...
- python---Memcached
Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...
- activiti自定义流程之整合(五):启动流程时获取自定义表单
流程定义部署之后,自然就是流程定义列表了,但和前一节一样的是,这里也是和之前单独的activiti没什么区别,因此也不多说.我们先看看列表页面以及对应的代码,然后在一步步说明点击启动按钮时如何调用自定 ...
- SQL Server 2012 使用警报调度数据库作业通知操作员
如果想让数据库满足某种条件时,触动警报,然后执行一系列作业,并通知管理员,则需要配置警报 比如,当数据库日志达到一定大小如10M时触动警报,执行以下3个作业步骤:备份日志.收缩日志文件到2M.完备数据 ...