1 条题解
-
0
C :
#include<stdio.h> int x,y,n,a[100][4],min=9999,ans,minn=9999; int abs(int a) { return (x>0?x:-x); } int main() { scanf("%d %d %d",&x,&y,&n); for(int i=1;i<=n;i++) { scanf("%d %d",&a[i][0],&a[i][1]); a[i][2]=abs(a[i][0]-x)+abs(a[i][1]-y); a[i][3]=abs(a[i][0])+abs(a[i][1]); if(a[i][2]==0) continue; if(a[i][2]<min) { min=a[i][2]; ans=i; } if(a[i][2]==min&&a[i][3]<minn) { minn=a[i][3]; ans=i; } } printf("%d %d\n",a[ans][0],a[ans][1]); return 0; }
C++ :
#include <bits/stdc++.h> using namespace std; //求从x y点走到t1 t2点需要花费的距离 int nums(int x,int y,int t1,int t2){ return abs(x - t1) + abs(y - t2); } int a[10000][2]; int main(){ int x,y,n,i,j,r1,r2;//r1和r2存放结果 cin>>x>>y; cin>>n; int maxlen = 300; int s; for(i = 0; i < n;i++){ cin>>a[i][0]>>a[i][1]; if(a[i][0] == x && a[i][1] == y){ continue; } s = nums(x,y,a[i][0],a[i][1]); if(s < maxlen){ r1 = a[i][0]; r2 = a[i][1]; maxlen = s; }else if(s == maxlen){ if(a[i][0] + a[i][1] < r1 + r2){ r1 = a[i][0]; r2 = a[i][1]; } } } cout<<r1<<" "<<r2<<endl; return 0; }
- 1
信息
- ID
- 2267
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者