坑nyoj1088 just do it
来源:互联网 发布:知乎 电脑客户端 编辑:程序博客网 时间:2024/06/07 00:27
Just do it
时间限制:2000 ms | 内存限制:65535 KB
难度:1
- 描述
- 给出n个点的坐标,输出斜率最大的两个点的坐标。
- 输入
- 第一行输入一个数N(不少于20000),表示有N组测试数据。每组测试数据首先输入一个数n(2<=n<=200),表示有n个点,接下来是n个点的坐标(坐标都是整数,-1000<x,y<1000)。
- 输出
- 每组测试数据输出占一行,输出斜率最大的两个点的坐标(横坐标小的先输出)。两组测试数据之间输出两个空行。
- 样例输入
232 53 74 751 32 74 13 94 3
- 样例输出
2 53 74 14 3
- 来源
- 原创
- 上传者
- ACM_尹玉娇思路:就是一点要注意 斜率最大点必定是相邻点 然后就是要用scanf 和 printf(我就跪在这里)
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{ int x,y;}p[210];int cmp(node a,node b){ if(a.x==b.x) return a.y<b.y; return a.x<b.x;}double kk(node a,node b){ return (a.y*1.0-b.y)/(a.x*1.0-b.x);}int main(){ int t; cin>>t; while(t--) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&p[i].x,&p[i].y); //cin>>p[i].x>>p[i].y; } sort(p,p+n,cmp); if(p[0].x==p[1].x) { if(p[0].y<p[1].y) printf("%d %d\n%d %d\n",p[0].x,p[0].y,p[1].x,p[1].y); //cout<<p[0].x<<" "<<p[0].y<<" "<<p[1].x<<" "<<p[1].y<<endl; else printf("%d %d\n%d %d\n",p[1].x,p[1].y,p[0].x,p[0].y); //cout<<p[1].x<<" "<<p[1].y<<" "<<p[0].x<<" "<<p[0].y<<endl; puts(""); continue; } double max=kk(p[0],p[1]); double max1; int flag =0,flag1=0; for(int i=1;i<n-1;i++) { if(p[i].x==p[i+1].x) { if(p[i].y<p[i+1].y) { printf("%d %d\n%d %d\n",p[i].x,p[i].y,p[i+1].x,p[i+1].y); //cout<<p[i].x<<" "<<p[i].y<<endl<<p[i+1].x<<" "<<p[i+1].y<<endl; } else { printf("%d %d\n%d %d\n",p[i+1].x,p[i+1].y,p[i].x,p[i].y); //cout<<p[i+1].x<<" "<<p[i+1].y<<endl<<p[i].x<<" "<<p[i].y<<endl; } puts(""); flag1=1; break; } max1=kk(p[i],p[i+1]); if(max1>max) { max=max1; flag=i; } } if(flag1==0) { printf("%d %d\n%d %d\n",p[flag].x,p[flag].y,p[flag+1].x,p[flag+1].y); puts(""); } }}
0 0
- 坑nyoj1088 just do it
- Just do it
- Just do it!
- Just do it!
- Just do it!
- just do it!
- Just do it!
- Just do it...
- Just do it
- Just do it!
- Just do it
- Just do it!
- just do it
- Just do it
- Just do it!
- just do it
- just do it
- Just do it
- php 重写的调用以及$this理解
- hdoj_Operation the Sequence_5063
- (转)VmWare下安装CentOS6图文安装教程
- Big Number
- spring 注入之 xml
- 坑nyoj1088 just do it
- 第7周项目3(2)-求三数最大值
- 【LeetCode】Balanced Binary Tree 解题报告
- 程序员:伤不起的三十岁
- 修改LDAP的rootDN
- mysql使用substring分割参数实例
- Java排序算法(三):堆排序
- Java排序算法(二):直接选择排序
- 【Unix 网络编程】UDP 客户/服务器简单 Socket 程序