链接 : http://poj.org/problem?id=1054

题意:

有一个r*c的方格,青蛙会以相同的向量v=(x,y)跳过,跳过的地方留下痕迹,青蛙在格子外哪里出发都有可能,问有最多有多少只青蛙;

思路:

先把点排序, 使其有序化, 然后枚举任意两点所在的直线, 看有多少点落在直线上, 求其最大值;

View Code

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <string>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <cstdlib>
 8 using namespace std;
 9 const int M=5005;
10 int R, C, N, x, y;
11 struct Point
12 {
13     int x, y;
14     bool operator < ( const Point &a ) const {
15         if( x==a.x )
16             return y<a.y;
17         return x<a.x;
18     }
19 }p[M];
20
21 int cmp( const void *e1, const void *e2 )
22 {
23     Point *p1, *p2;
24     p1 = (Point*) e1;
25     p2 = (Point*) e2;
26     if ( p1->x == p2->x ) return( p1->y - p2->y );
27     return ( p1->x - p2->x );
28 }
29 int AC( Point po, int dX, int dY ){
30     Point plant;
31     int temp;
32     plant.x = po.x + dX;
33     plant.y = po.y + dY;
34     temp = 2;
35     while ( plant.x <= R && plant.x >= 1 && plant.y <= C && plant.y >= 1 ) {
36         if ( !bsearch(&plant, p, N, sizeof(Point),cmp) ) {  // 在所有点中二分查找该点是否存在.
37             temp = 0;
38                break;
39         }
40         plant.x += dX;
41         plant.y += dY;
42         temp++;
43     }
44     return( temp );
45 }
46
47 int main( )
48 {
49     while( scanf( "%d%d", &R, &C )==2 ){
50         scanf( "%d", &N );
51         for( int i=0; i<N; ++ i ){
52             scanf( "%d%d", &x, &y );
53             p[i]=(Point){x, y} ;
54         }
55         sort( p, p+N );
56         int dx, dy, px, py, max=2;
57
58         for( int i=0; i<N-2; ++ i ){
59             for( int j=i+1; j<N-1; ++ j ){
60                 dx=p[j].x-p[i].x, dy=p[j].y-p[i].y;
61                 px=p[i].x-dx, py=p[i].y-dy;
62                 if ( px <= R && px >= 1 && py <= C && py >= 1 ) continue;// 没出去 , 不合题意
63                 if( p[i].x+max*dx>R )break; //  当前点,到位置加上max倍的距离已经出界, 所以temp最大不超过max, 不会更新max
64                 py = p[i].y + max * dy;
65                 if ( py > C || py < 1) continue; // 同上
66                 int temp = AC( p[j], dx, dy );
67                 if ( temp > max )  max = temp;
68             }
69         }
70         if ( max == 2 ) max = 0;
71             printf("%d\n", max);
72
73     }
74     return 0;
75 }

转载于:https://www.cnblogs.com/jian1573/archive/2013/01/15/2860670.html

poj1054The Troublesome FrogDP相关推荐

  1. 18.06.27 POJ1054 The Troublesome Frog

    描述 In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a well-deserv ...

  2. POJ 1054 The Troublesome Frog(枚举 + 剪枝)

    题意: http://blog.csdn.net/politropix/article/details/8456551 思路: 1. 首先针对 x 从小到大排序,然后枚举,这样为后面的剪枝提供了方便; ...

  3. Bailian2812 恼人的青蛙 POJ1054 The Troublesome Frog【暴力】

    2812:恼人的青蛙 总时间限制: 2000ms 单个测试点时间限制: 500ms 内存限制: 65536kB 描述 在韩国,有一种小的青蛙.每到晚上,这种青蛙会跳越稻田,从而踩踏稻子.农民在早上看到 ...

  4. docker容器虚拟化技术_Docker,虚拟机和容器的全面介绍

    docker容器虚拟化技术 by shota jolbordi 通过Shota Jolbordi Docker has been a buzzword for tech people for the ...

  5. 您需要了解有关Angular中的ng-template,ng-content,ng-container和* ngTemplateOutlet的所有信息...

    It was one of those days when I was busy working on new features for my office project. All a sudden ...

  6. 关系数据库非关系数据库_如何与关系数据库最佳配合

    关系数据库非关系数据库 Relational databases handle data smoothly, whether working with small volumes or process ...

  7. Beyond MySQL --Branching the popular database--转载

    原文:http://www.ibm.com/developerworks/library/os-beyondmysql/ Introduction MySQL is one of the most p ...

  8. 使用 ftrace 调试 Linux 内核【转】

    转自:http://blog.csdn.net/adaptiver/article/details/7930646 使用 ftrace 调试 Linux 内核,第 1 部分 http://blog.c ...

  9. ACM题集以及各种总结大全(转)

    ACM题集以及各种总结大全! 虽然退役了,但是整理一下,供小弟小妹们以后切题方便一些,但由于近来考试太多,顾退役总结延迟一段时间再写!先写一下各种分类和题集,欢迎各位大牛路过指正. 一.ACM入门 关 ...

  10. 什么是“.NET Core”?

    本文翻译自:What is ".NET Core"? Recently in an official .NET Framework Blog it was announced th ...

最新文章

  1. Spring越来越强,而我们越来越快餐!离开了Spring,居然API都写不出来了! 程序猿DD...
  2. 近400万奖金!2021全国人工智能大赛来了
  3. 为什么阿里规定需要在事务注解 @Transactional 中指定 rollbackFor?
  4. 解决ecilpse插件安装速度变得很慢
  5. GG and MM(every sg 游戏)
  6. gradle构建多模块项目_Gradle入门:创建多项目构建
  7. Binary String Matching(C++)
  8. 小程序助手多功能微信小程序反编译工具
  9. Python实现双端队列
  10. 利用数据库来填充UltraWebTree
  11. El 表达式、jstl学习
  12. 4-2 面向复用的软件构造技术
  13. 2021年下半年软考真题软件设计师真题答案(下午题)
  14. 多视图几何三维重建实战系列之COLMAP
  15. P80 例4-1 名和姓的对换问题。英国人和美国人姓名的书写形式是“名在前,姓在后”,但在有些情况下,需要把姓名写成“姓在前,名在后,中间加一个逗号”的形式。编写一个程序实现把“名在前,姓在后”的姓名
  16. java去处科学技术法,java撤销科学计数法
  17. 【百问网智能家居---基于单片机最小系统STM32F103C8T6_MINI的入门学习】
  18. 咸鱼的 GitHub 情报 | 20200103 期
  19. FFmpeg提取视频(mp4)中的音频(m4a)
  20. 下载stm32f4xx标准外设库

热门文章

  1. 解压 .solitairetheme8 文件
  2. memcpy-avx-unaligned/strcpy_sse2_unaligned崩溃记录
  3. 没钱发工资?当着董事长总经理是好玩的,不用负责?
  4. Ubuntu 16上命令行提示长目录的解决办法
  5. mysql.server的路径_WindowsMysqlServer重启,log-bin路径配置
  6. html5中布局命名,HTML5 发展中的命名约定和微格式
  7. java 原型模式的应用_java中原型模式详解和使用方法
  8. 全国一级计算机基础及ps题目,一级计算机基础及Photoshop应用模拟试题(14)
  9. c++语言函数参数传递方式,C++函数传递三种方式解读
  10. PHP图片水印右下角,php图片水印处理