HDU 2022
来源:互联网 发布:php写api接口实例 编辑:程序博客网 时间:2024/04/26 01:39
这是一道非常水的排序题,只不过是将原来我们经常做的一维数组问题转化为二维数组,把一般的数值排序问题转化为绝对值的排序问题,但是题目相对来说没什么难度,可是第一次写的这个WA了3次,不知道是怎么错的,请大家帮我看看,,知道的M下,谢谢了~
# include<cstdio># include<iostream># include<cstring># include<cmath>using namespace std;# define MAX 10000# define xh1 int i = 1;i <= n;i++# define xh2 int j = 1;j <= m;j++long a[MAX+10][MAX+10];int main(void){ int n,m; int flag = 0; memset(a,0,sizeof(a)); while ( cin>>n>>m ) { for ( xh1 ) { for ( xh2 ) { cin>>a[i][j]; } } int max = abs(a[0][0]); for ( xh1 ) { for ( xh2 ) { for ( int k = j;k <= m;k++ ) { if ( max <= abs(a[i][k]) ) { max = abs(a[i][j]); } } } } int max2 = -max; for ( xh1 ) { for ( xh2 ) { if ( a[i][j]== max2 ) { cout<<i<<" "<<j<<" "<<max2<<endl; flag = 1; break; } if ( a[i][j] == max ) { cout<<i<<" "<<j<<" "<<max<<endl; flag = 1; break; } } if ( flag ) break; } //cout<<max2<<endl; } return 0;}
于是转化思路,用结构体的思想来处理这个问题,下面是代码:
# include<cstdio># include<iostream># include<algorithm>using namespace std;# define MAX 10000# define xh1 int i = 1;i <= n;i++# define xh2 int j = 1;j <= m;j++struct node{ int m; int x; int y;}w[MAX+10];bool compare( node x2,node y2 ){ if ( abs(x2.m)>abs(y2.m) ) return true; if ( abs(x2.m)==abs(y2.m)&&x2.x<y2.x ) return true; if ( abs(x2.m)==abs(y2.m)&&x2.x==y2.x&&x2.y<y2.y ) return true; return false;}int main(void){ int n,m,q; while ( cin>>n>>m ) { int ans = 0; for ( xh1 ) { for ( xh2 ) { cin>>q; w[ans].x = i; w[ans].y = j; w[ans].m = q; ans++; } } sort(w,w+ans,compare); cout<<w[0].x<<" "<<w[0].y<<" "<<w[0].m<<endl; } return 0;}
0 0
- HDU 2022
- hdu 2022
- HDU 2022
- HDU-2022
- HDU 2022
- HDU 2022
- hdu 2022
- hdu 2022
- HDU-2022
- hdu 2022 海选女主角
- HDU 2022 海选女主角
- HDU 2022 海选女主角
- hdu 2022 海选女主角
- hdu oj 2022
- HDU 2022 - 海选女主角
- hdu-2022-海选女主角
- [hdu 2022] 海选女主角
- HDU 2022 海选女主角
- 『IOS』Core Data Libraries & Utilities
- LeetCode: Search a 2D Matrix
- 多线程篇3 线程的状态与调度
- 维盟路由器 交换机 无线AP
- Android 点击按钮上下翻页图片
- HDU 2022
- Leetcode: Evaluate Reverse Polish Notation
- Android DatePicker 只显示年月日不显示月历的两种方法
- CentOS 7 快速架设hadoop 2.5.1集群
- Android面试题精选
- iOS NSStream TCP Socket iPhone 客户端实现效果
- Java 8 特性 – 终极指南
- 802.11概述及帧结构分析
- Android 新建低版本项目,无法选择BlankActivity模版