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 ...
随机推荐
- 简单介绍Javascript匿名函数和面向对象编程
忙里偷闲,简单介绍一下Javascript中匿名函数和闭包函数以及面向对象编程.首先简单介绍一下Javascript中的密名函数. 在Javascript中函数有以下3中定义方式: 1.最常用的定义方 ...
- ASP.Net Session, Cookie, Cache的区别
Session—管理用户会话状态 什么是状态管理? 指对同一页或不同页的多个请求维护状态和页信息的过程 为什么要进行状态管理? Web页是无状态的,不保存任何用户请求信息,而且到服务器的每一往返过程都 ...
- webpack脚手架搭建(简单版)
运行命令 安装依赖:npm install 运行项目:npm start 大致流程 npm init:新建 package.json 将需要的依赖模块加入 dependencies(生产环境) 和 d ...
- surge for mac出测试版本了
这两天一直在MAC上试图连接我的shadowsocks服务,使用shadowsocksX一直没能连接到服务器.服务器本身是没有问题的,因为我的thinkpad和iphone都可以正常使用.结果就试着使 ...
- 循环神经网络(RNN, Recurrent Neural Networks)介绍(转载)
循环神经网络(RNN, Recurrent Neural Networks)介绍 这篇文章很多内容是参考:http://www.wildml.com/2015/09/recurrent-neur ...
- HDU 1372 Knight Moves (bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1372 Knight Moves Time Limit: 2000/1000 MS (Java/Othe ...
- 渴切API参考手册
渴切:是国内优秀的开源css框架. 渴切是一个开源中文 (X)HTML/CSS 框架 ,它的目的是减少你的css开发时间.它提供一个可靠的css基础去创建你的项目,能够用于网站的快速设计,通过重设和重 ...
- [原创]cocos2d-x研习录-第二阶 概念类之节点类(CCNode)
节点类CCNode在基本概念中并不存在,它是为了建立基本概念之间的关联关系而抽象出来的中间辅助类.这个类在Cocos2D-x中极为重要,它为概念类之间搭建了一座宏伟的桥梁.它的继承关系图如下: ...
- JUQERY 获取同名称的所有CHECKBOX ,获取已经选择的,并且jquery进行勾选!
var @(Perfix)_CheckArray=[]; @(Perfix)_CheckArray.length=0; var checkedItems = $('input[name="@ ...
- 【solr】java整合solr5.0之solrj的使用
1.首先导入solrj需要的的架包 2.需要注意的是低版本是solr是使用SolrServer进行URL实例的,5.0之后已经使用SolrClient替代这个类了,在添加之后首先我们需要根据schem ...