“玲珑杯”ACM比赛 Round #4 G -- See car【多种容器的运用】
来源:互联网 发布:无涯子 知乎 编辑:程序博客网 时间:2024/06/04 17:55
1052 - See car
Time Limit:2s Memory Limit:64MByte
Submissions:569Solved:215
DESCRIPTION
You are the god of cars, standing at (a, b) point.There are some cars at point (xi,yi)(xi,yi). If lots of cars and you are in one line, you can only see the car that is nearest to yourself. How many cars can you see?
It is guaranteed that xi>axi>a and yi>byi>b.
INPUT
There are multiple test cases.The first line is a number T (T ≤11 ≤11), which means the number of cases.For each case, first line has three integers a,b,n(−109≤a,b≤109,0≤n≤105)a,b,n(−109≤a,b≤109,0≤n≤105).nextnn lines, each line contains two integer (xi,yi)(−109≤xi,yi≤109)(xi,yi)(−109≤xi,yi≤109), which means the position of car.
OUTPUT
one line --- the number of car that you can see.
SAMPLE INPUT
2
0 0 3
1 1
2 2
3 3
0 0 4
1 1
2 2
2 3
4 6
SAMPLE OUTPUT
1
2
SOLUTION
“玲珑杯”ACM比赛 Round #4
原题链接:http://www.ifrog.net/acm/problem/1052
题意:给出自己的所在点(x,y),再给出其他车的所在坐标(xi,yi),(xi>x,yi>y),问你从自己所在位置最多能看到多少辆车,每一个方向只能看到这个方向的第一辆车。
就是说以(x,y)为起点的射线数量,给了那个条件就更简单了,消除了斜率为0和不存在的情况。这样的话判断一下斜率有多少种就可以了。
对于斜率的存储方法可以有三种:
1:double 型数组,这个很简单,拍下序就可以了。
2:map<double,int>mp;
3:set<double>se。
对于下面两种容器,最后统计的时候大小的时候可以有个小优化。
AC代码1:
/** * 行有余力,则来刷题! * 博客链接:http://blog.csdn.net/hurmishine **/#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int maxn=1e5+5;double a[maxn];int main(){ //freopen("data.txt","r",stdin); int T; cin>>T; while(T--) { int x,y,t; cin>>x>>y>>t; int xx,yy; int k=0; while(t--) { cin>>xx>>yy; a[k++]=(yy-y)*1.0/(xx-x); } sort(a,a+k); int ans=1; for(int i=1;i<k;i++) { if(a[i]!=a[i-1]) ans++; } cout<<ans<<endl; } return 0;}
AC代码2:
/** * 行有余力,则来刷题! * 博客链接:http://blog.csdn.net/hurmishine **/#include <iostream>#include <cstdio>#include <algorithm>#include <map>using namespace std;const int maxn=1e5+5;double a[maxn];int main(){ //freopen("data.txt","r",stdin); int T; cin>>T; map<double,int>mp; while(T--) { int x,y,t; cin>>x>>y>>t; int xx,yy; mp.clear(); while(t--) { cin>>xx>>yy; double k=(yy-y)*1.0/(xx-x); if(mp.count(k)==0) mp[k]=1; } cout<<mp.size()<<endl; } return 0;}
AC代码3:
/** * 行有余力,则来刷题! * 博客链接:http://blog.csdn.net/hurmishine **/#include <iostream>#include <cstdio>#include <algorithm>#include <set>using namespace std;const int maxn=1e5+5;double a[maxn];int main(){ //freopen("data.txt","r",stdin); int T; cin>>T; set<double>se; while(T--) { int x,y,t; cin>>x>>y>>t; int xx,yy; se.clear(); int ans=0; while(t--) { cin>>xx>>yy; double k=(yy-y)*1.0/(xx-x); if(se.find(k)==se.end()) { ans++; se.insert(k); } } //cout<<se.size()<<endl; cout<<ans<<endl; } return 0;}
尊重原创,转载请注明出处:http://blog.csdn.net/hurmishine
0 0
- “玲珑杯”ACM比赛 Round #4 G -- See car【多种容器的运用】
- “玲珑杯”ACM比赛 Round #4 G -- See car
- 玲珑杯”ACM比赛 Round #4 G -- See car【Set】
- 玲珑杯1052 - See car——STL集合的应用(“玲珑杯”ACM比赛 Round #4 )
- 玲珑Round #4-G -- See car
- “玲珑杯”ACM比赛 Round #4
- 玲珑杯-【See car】
- 玲珑杯”ACM比赛 Round #5 --2的幂次方
- “玲珑杯”ACM比赛 Round #4 A -- chess play
- “玲珑杯”ACM比赛 Round #4 E -- array(dp)
- “玲珑杯”ACM比赛 Round #4 E题
- 玲珑杯”ACM比赛 Round #4 E -- array【DP】
- “玲珑杯”ACM比赛 Round #4 B Best couple
- 玲珑杯”ACM比赛 Round #5
- “玲珑杯”ACM比赛 Round #7
- “玲珑杯”ACM比赛 Round #7
- “玲珑杯”ACM比赛 Round #11 " ---1097
- “玲珑杯”ACM比赛 Round #11 D
- SVG文档的注意事项
- 重磅 | 微信应用号,小程序最新开发教程第一弹
- FZU2150 fire
- iOS 第三方JASidePanels侧滑
- jsp中静态包含和动态包含有什么区别?
- “玲珑杯”ACM比赛 Round #4 G -- See car【多种容器的运用】
- ubuntu下C/C++ 环境安装
- 适配器设计模式的简要概括
- 线程之间的互斥和同步
- 解决od复制到可执行文件中没有所有修改的bug
- windows.onload的作用
- 解决360篡改谷歌或其他浏览器主页的问题(亲身经历绝不copy)
- myeclipse常用快捷键
- source tree 更改远程的仓库的地址