扫描线三巨头 hdu1928hdu 1255 hdu 1542 [POJ 1151]

学习链接:http://blog.csdn.net/lwt36/article/details/48908031

学习扫描线主要学习的是一种扫描的思想,后期可以求解很多问题。

 

扫描线求矩形周长并

hdu 1928

Picture

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4795    Accepted Submission(s): 2339


Problem Description
A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wall. Their sides are all vertical or horizontal. Each rectangle can be partially or totally covered by the others. The length of the boundary of the union of all rectangles is called the perimeter. 

Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1. 



The corresponding boundary is the whole set of line segments drawn in Figure 2. 



The vertices of all rectangles have integer coordinates.

 

Input
Your program is to read from standard input. The first line contains the number of rectangles pasted on the wall. In each of the subsequent lines, one can find the integer coordinates of the lower left vertex and the upper right vertex of each rectangle. The values of those coordinates are given as ordered pairs consisting of an x-coordinate followed by a y-coordinate. 

0 <= number of rectangles < 5000 
All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.

Please process to the end of file.

 

Output
Your program is to write to standard output. The output must contain a single line with a non-negative integer which corresponds to the perimeter for the input rectangles.

 

Sample Input
7 -15 0 5 10 -5 8 20 25 15 -4 24 14 0 -6 16 4 2 15 10 22 30 10 36 20 34 0 40 16

 

Sample Output
228

 

Source
IOI 1998

 

Recommend
linle

  1 //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2 #include<cstdio>
  3 #include<iostream>
  4 #include<cstring>
  5 #include<algorithm>
  6 #include<cmath>
  7 #define clr(x) memset(x,0,sizeof(x))
  8 #define MAXN 50010
  9 using namespace std;
 10 struct edgx
 11 {
 12     int l,u,x;
 13     int d;
 14 }edgex[MAXN];
 15 struct edgy
 16 {
 17     int l,r,y;
 18     int d;
 19 }edgey[MAXN];
 20 struct seg
 21 {
 22     int l,r,cov,len;
 23 }segt[MAXN<<2];
 24 int cntx,cnty;
 25 int x[MAXN],y[MAXN],vec[MAXN];
 26 bool cmpy(edgy a,edgy b)
 27 {
 28     if(a.y==b.y) return a.d>b.d;
 29     return a.y<b.y;
 30 }
 31 bool cmpx(edgx a,edgx b)
 32 {
 33     if(a.x==b.x) return a.d>b.d;
 34     return a.x<b.x;
 35 }
 36 void init(int i,int l,int r)
 37 {
 38     segt[i]=(seg){l,r,0,0};
 39     if(l==r)
 40         return ;
 41     int mid=(l+r)>>1;
 42     init(i<<1,l,mid);
 43     init(i<<1|1,mid+1,r);
 44     return ;
 45 }
 46 void pushup(int i)
 47 {
 48     if(segt[i].cov)
 49     {
 50         segt[i].len=vec[segt[i].r+1]-vec[segt[i].l];
 51     }
 52     else if(segt[i].l==segt[i].r)
 53     {
 54         segt[i].len=0;
 55     }
 56     else
 57     {
 58         segt[i].len=segt[i<<1].len+segt[i<<1|1].len;
 59     }
 60     return ;
 61 }
 62 void update(int i,int l,int r,int value)
 63 {
 64     if(segt[i].l>=l && segt[i].r<=r)
 65     {
 66         segt[i].cov+=value;
 67         pushup(i);
 68         return ;
 69     }
 70     int mid=(segt[i].l+segt[i].r)>>1;
 71     if(mid>=r)
 72     {
 73         update(i<<1,l,r,value);
 74     }
 75     else if(mid<l)
 76     {
 77         update(i<<1|1,l,r,value);
 78     }
 79     else
 80     {
 81         update(i<<1,l,r,value);
 82         update(i<<1|1,l,r,value);
 83     }
 84     pushup(i);
 85     return ;
 86 }
 87 int main()
 88 {
 89     int x1,x2,y1,y2,n,m,T,ans,l,r,k;
 90     while(scanf("%d",&n)!=EOF)
 91     {
 92         cntx=0;
 93         cnty=0;
 94         for(int i=1;i<=n;i++)
 95         {
 96             scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
 97             edgex[++cntx]=(edgx){y1,y2,x1,1};
 98             x[cntx]=x1;
 99             edgex[++cntx]=(edgx){y1,y2,x2,-1};
100             x[cntx]=x2;
101             edgey[++cnty]=(edgy){x1,x2,y1,1};
102             y[cnty]=y1;
103             edgey[++cnty]=(edgy){x1,x2,y2,-1};
104             y[cnty]=y2;
105         }
106         n<<=1;
107         ans=0;
108         memcpy(vec,x,sizeof(x));
109         sort(vec+1,vec+n+1);
110         m=unique(vec+1,vec+n+1)-vec-1;
111         sort(edgey+1,edgey+n+1,cmpy);
112         init(1,1,m);
113         for(int i=1;i<=n;i++)
114             if(edgey[i].l<edgey[i].r)
115             {
116                 k=segt[1].len;
117                 l=lower_bound(vec+1,vec+m+1,edgey[i].l)-vec;
118                 r=lower_bound(vec+1,vec+m+1,edgey[i].r)-vec;
119                 update(1,l,r-1,edgey[i].d);
120                 ans+=abs(segt[1].len-k);
121             }
122         memcpy(vec,y,sizeof(y));
123         sort(vec+1,vec+n+1);
124         m=unique(vec+1,vec+n+1)-vec-1;
125         sort(edgex+1,edgex+n+1,cmpx);
126         init(1,1,m);
127         for(int i=1;i<=n;i++)
128             if(edgex[i].l<edgex[i].u)
129             {
130                 k=segt[1].len;
131                 l=lower_bound(vec+1,vec+m+1,edgex[i].l)-vec;
132                 r=lower_bound(vec+1,vec+m+1,edgex[i].u)-vec;
133                 update(1,l,r-1,edgex[i].d);
134                 ans+=abs(segt[1].len-k);
135             }
136         printf("%d\n",ans);
137     }
138     return 0;
139 }

 

hdu 1255 矩阵面积交

覆盖的面积

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5718    Accepted Submission(s): 2854


Problem Description
给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.

 

Input
输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1<=N<=1000),代表矩形的数量,然后是N行数据,每一行包含四个浮点数,代表平面上的一个矩形的左上角坐标和右下角坐标,矩形的上下边和X轴平行,左右边和Y轴平行.坐标的范围从0到100000.

注意:本题的输入数据较多,推荐使用scanf读入数据.

 

Output
对于每组测试数据,请计算出被这些矩形覆盖过至少两次的区域的面积.结果保留两位小数.

 

Sample Input
2 5 1 1 4 2 1 3 3 7 2 1.5 5 4.5 3.5 1.25 7.5 4 6 3 10 7 3 0 0 1 1 1 0 2 1 2 0 3 1

 

Sample Output
7.63 0.00

 

Author
Ignatius.L & weigang Lee

  1 //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2 #include<cstdio>
  3 #include<iostream>
  4 #include<cstring>
  5 #include<algorithm>
  6 #include<cmath>
  7 #define clr(x) memset(x,0,sizeof(x))
  8 #define MAXN 10010
  9 using namespace std;
 10 struct edg
 11 {
 12     double l,r,y;
 13     int d;
 14 }edge[MAXN];
 15 struct seg
 16 {
 17     int l,r,cov;
 18     double len1,len2;
 19 }segt[MAXN<<2];
 20 int cnt;
 21 double x[MAXN];
 22 bool cmp(edg a,edg b)
 23 {
 24     if(a.y==b.y) return a.d>b.d;
 25     return a.y<b.y;
 26 }
 27 double max(double a,double b)
 28 {
 29     return a>b?a:b;
 30 }
 31 void init(int i,int l,int r)
 32 {
 33     segt[i]=(seg){l,r,0,0,0};
 34     if(l==r)
 35         return ;
 36     int mid=(l+r)>>1;
 37     init(i<<1,l,mid);
 38     init(i<<1|1,mid+1,r);
 39     return ;
 40 }
 41 void pushup(int i)
 42 {
 43     if(segt[i].cov>=2)
 44     {
 45         segt[i].len2=segt[i].len1=x[segt[i].r+1]-x[segt[i].l];
 46     }
 47     else if(segt[i].cov==1)
 48     {
 49         segt[i].len1=x[segt[i].r+1]-x[segt[i].l];
 50         if(segt[i].l==segt[i].r)
 51             segt[i].len2=0;
 52         else
 53             segt[i].len2=max(segt[i<<1].len1,segt[i<<1].len2)+max(segt[i<<1|1].len1,segt[i<<1|1].len2);
 54     }
 55     else
 56     {
 57         if(segt[i].l==segt[i].r)
 58         {
 59             segt[i].len1=segt[i].len2=0;
 60         }
 61         else
 62         {
 63             segt[i].len2=segt[i<<1].len2+segt[i<<1|1].len2;
 64             segt[i].len1=segt[i<<1].len1+segt[i<<1|1].len1;
 65         }
 66     }
 67     return ;
 68 }
 69 void update(int i,int l,int r,int value)
 70 {
 71     if(segt[i].l>=l && segt[i].r<=r)
 72     {
 73         segt[i].cov+=value;
 74         pushup(i);
 75         return ;
 76     }
 77     int mid=(segt[i].l+segt[i].r)>>1;
 78     if(mid>=r)
 79     {
 80         update(i<<1,l,r,value);
 81     }
 82     else if(mid<l)
 83     {
 84         update(i<<1|1,l,r,value);
 85     }
 86     else
 87     {
 88         update(i<<1,l,r,value);
 89         update(i<<1|1,l,r,value);
 90     }
 91     pushup(i);
 92     return ;
 93 }
 94 int main()
 95 {
 96     int T,n,m,k,u,v;
 97     double x1,x2,y1,y2,ans,l,r;
 98     scanf("%d",&T);
 99     while(T--)
100     {
101         scanf("%d",&n);
102         cnt=0;
103         ans=0;
104         for(int i=1;i<=n;i++)
105         {
106             scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
107             edge[++cnt]=(edg){x1,x2,y1,1};
108             x[cnt]=x1;
109             edge[++cnt]=(edg){x1,x2,y2,-1};
110             x[cnt]=x2;
111         }
112         n<<=1;
113         sort(x+1,x+n+1);
114         m=unique(x+1,x+n+1)-x-1;
115         sort(edge+1,edge+n+1,cmp);
116         init(1,1,m);
117         for(int i=1;i<n;i++)
118             if(edge[i].r>edge[i].l)
119             {
120                 l=lower_bound(x+1,x+m+1,edge[i].l)-x;
121                 r=lower_bound(x+1,x+m+1,edge[i].r)-x;
122                 update(1,l,r-1,edge[i].d);
123                     ans+=segt[1].len2*(edge[i+1].y-edge[i].y);
124             }
125         printf("%0.2lf\n",ans);
126     }
127     return 0;
128 }

 

 

hdu 1542 [POJ 1151] 区间面积并

Atlantis

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12537    Accepted Submission(s): 5257


Problem Description
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe different regions of Atlantis. Your friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to write a program that calculates this quantity.

 

Input
The input file consists of several test cases. Each test case starts with a line containing a single integer n (1<=n<=100) of available maps. The n following lines describe one map each. Each of these lines contains four numbers x1;y1;x2;y2 (0<=x1<x2<=100000;0<=y1<y2<=100000), not necessarily integers. The values (x1; y1) and (x2;y2) are the coordinates of the top-left resp. bottom-right corner of the mapped area.

The input file is terminated by a line containing a single 0. Don’t process it.

 

Output
For each test case, your program should output one section. The first line of each section must be “Test case #k”, where k is the number of the test case (starting with 1). The second one must be “Total explored area: a”, where a is the total explored area (i.e. the area of the union of all rectangles in this test case), printed exact to two digits to the right of the decimal point.

Output a blank line after each test case.

 

Sample Input
2 10 10 20 20 15 15 25 25.5 0

 

Sample Output
Test case #1 Total explored area: 180.00

 

Source
Mid-Central European Regional Contest 2000

卡格式,不说了,都是泪。
  1 //#pragma comment(linker, "/STACK:1024000000,1024000000")
  2 #include<cstdio>
  3 #include<iostream>
  4 #include<cstring>
  5 #include<algorithm>
  6 #include<cmath>
  7 #define clr(x) memset(x,0,sizeof(x))
  8 #define MAXN 10010
  9 using namespace std;
 10 struct edg
 11 {
 12     double l,r,y;
 13     int d;
 14 }edge[MAXN];
 15 struct seg
 16 {
 17     int l,r,cov;
 18     double len;
 19 }segt[MAXN<<2];
 20 int cnt;
 21 double x[MAXN];
 22 bool cmp(edg a,edg b)
 23 {
 24     if(a.y==b.y) return a.d>b.d;
 25     return a.y<b.y;
 26 }
 27 double max(double a,double b)
 28 {
 29     return a>b?a:b;
 30 }
 31 void init(int i,int l,int r)
 32 {
 33     segt[i]=(seg){l,r,0,0};
 34     if(l==r)
 35         return ;
 36     int mid=(l+r)>>1;
 37     init(i<<1,l,mid);
 38     init(i<<1|1,mid+1,r);
 39     return ;
 40 }
 41 void pushup(int i)
 42 {
 43     if(segt[i].cov)
 44     {
 45         segt[i].len=x[segt[i].r+1]-x[segt[i].l];
 46     }
 47     else if(segt[i].l==segt[i].r)
 48     {
 49         segt[i].len=0;
 50     }
 51     else
 52     {
 53         segt[i].len=segt[i<<1].len+segt[i<<1|1].len;
 54     }
 55     return ;
 56 }
 57 void update(int i,int l,int r,int value)
 58 {
 59     if(segt[i].l>=l && segt[i].r<=r)
 60     {
 61         segt[i].cov+=value;
 62         pushup(i);
 63         return ;
 64     }
 65     int mid=(segt[i].l+segt[i].r)>>1;
 66     if(mid>=r)
 67     {
 68         update(i<<1,l,r,value);
 69     }
 70     else if(mid<l)
 71     {
 72         update(i<<1|1,l,r,value);
 73     }
 74     else
 75     {
 76         update(i<<1,l,r,value);
 77         update(i<<1|1,l,r,value);
 78     }
 79     pushup(i);
 80     return ;
 81 }
 82 int main()
 83 {
 84     int T,n,m,k,u,v;
 85     double x1,x2,y1,y2,ans,l,r;
 86     int kase=0;
 87     while(scanf("%d",&n) && n!=0)
 88     {
 89         printf("Test case #%d\n",++kase);
 90         cnt=0;
 91         ans=0;
 92         for(int i=1;i<=n;i++)
 93         {
 94             scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
 95             edge[++cnt]=(edg){x1,x2,y1,1};
 96             x[cnt]=x1;
 97             edge[++cnt]=(edg){x1,x2,y2,-1};
 98             x[cnt]=x2;
 99         }
100         n<<=1;
101         sort(x+1,x+n+1);
102         m=unique(x+1,x+n+1)-x-1;
103         sort(edge+1,edge+n+1,cmp);
104         init(1,1,m);
105         for(int i=1;i<n;i++)
106             if(edge[i].r>edge[i].l)
107             {
108                 l=lower_bound(x+1,x+m+1,edge[i].l)-x;
109                 r=lower_bound(x+1,x+m+1,edge[i].r)-x;
110                 update(1,l,r-1,edge[i].d);
111                     ans+=segt[1].len*(edge[i+1].y-edge[i].y);
112             }
113         printf("Total explored area: %0.2lf\n",ans);
114         printf("\n");
115     }
116     return 0;
117 }

 

转载于:https://www.cnblogs.com/wujiechao/p/6730638.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/572567.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

希尔排序 最坏时间_排序算法(2)

本文介绍插入排序和希尔排序&#xff0c;插入排序是较为常见的排序算法&#xff0c;希尔排序也是基础的排序算法&#xff0c;废话不多说&#xff0c;具体来看一下两种算法。山插入排序插入排序的基本思想是拿到下一个插入元素&#xff0c;在已经有序的待排数组部分找到自己的位…

题目1017:还是畅通工程(最小生成树初步应用)

题目链接&#xff1a;http://ac.jobdu.com/problem.php?pid1017 详解链接&#xff1a;https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码&#xff1a; // // 1017 还是畅通工程.cpp // Jobdu // // Created by PengFei_Zheng on 18/04/2017. // Copyright © 201…

maven自带clean_maven之clean、install命令

1、进入到maven根目录&#xff0c;执行mvn compile命令会在根目录生成target文件(参照maven之helloworld案例)&#xff0c;如下图&#xff1a;2、执行mvn clean可将根目录下生成的target文件移除3、mvn install命令Speak.java代码package com.maven;import com.maven.HelloWorl…

多对一(一对多)的双向关联

一个组&#xff08;Group&#xff09;有多个用户&#xff08;User&#xff09;&#xff0c;进行多对一&#xff08;一对多&#xff09;的双向配置&#xff0c;在数据库中生成的表结构如下图&#xff1a; Annotation配置&#xff1a; Group: 1 package com.bjsxt.hibernate;2 3 …

angularjs 同步請求_angularjs $q、$http 处理多个异步请求

在实际业务中经常需要等待几个请求完成后再进行下一步操作。但angularjs中$http不支持同步的请求。解决方法一&#xff1a;$http.get(url1).success(function (d1) {$http.get(url2).success(function (d2) {//处理逻辑});});解决方法二&#xff1a;then中的方法会按顺序执行。…

隧道不能访问web vxaln_SpringBoot实现本地存储文件上传及提供HTTP访问服务

笔者计划为大家介绍分布式文件系统&#xff0c;用于存储应用的图片、word、excel、pdf等文件。在开始介绍分布式文件系统之前&#xff0c;为大家介绍一下使用本机存储来存放文件资源。二者的核心实现过程是一样的&#xff1a;上传文件&#xff0c;保存文件(本节是本地磁盘)返回…

poj1986 Distance Queries(lca又是一道模版题)

题目链接&#xff1a;http://poj.org/problem?id1986 题意&#xff1a;就是老问题求val[u]val[v]-2*val[root]就行。还有这题没有给出不联通怎么输出那么题目给出的数据一定 是联通的。 题解&#xff1a;就是单纯的lca。 #include <iostream> #include <cstring> …

httpsurlconnection 写不进去authorization值_23. 假设检验的时候为什么常写p lt; 0.05,而不写具体的p值?...

在进行假设检验的时候&#xff0c;如果p值小于设定的临界值&#xff0c;比如0.05或0.01、0.001等&#xff0c;人们常常会写p<0.05、p<0.01、p<0.001, 而没有写具体的p值。这种传统是曾经的技术限制造成的&#xff0c;而在今天是不被提倡的&#xff0c;现代更提倡的是直…

修改form_Vue通过阿里云oss的url连接直接下载文件并修改文件名

我测试过很多遍,想要通过a标签的形式来直接点击url下载文件并重命名但是都失败了,最终只能下载却不能重命名 所以 换了java后台来修改名字.以下代码我做的网页是点击文件直接下载直接下载下来了,一开始的文件名是上传到oss时以id命名的名字,现在下载的时候想改名,遇到了问题,所…

支付宝 报错 rsa_private read error : private key is NULL解决方法

原因: 真机调试IOS支付宝功能GDB出现 rsa_private read error : private key is NULL提示 调试iOS 支付宝SDK的时候&#xff0c;执行demo。把Partner(合作商户 ID)Seller(账户 ID)RSA public key(支付宝公钥)RSA private key(商户私钥)执行的时候&#xff0c;报错 rsa_private…

nasa注册_今天是黑洞星期五!

What is a black hole? A black hole is an astronomical object with a gravitational pull so strong that nothing, not even light, can escape it. A black hole’s “surface,” called its event horizon, defines the boundary where the velocity needed to escape e…

Sort List[leetcode] 由归并排序的递归和循环,到本题的两种解法

归并排序能够有两种思路----top-down 和 bottom-up top-down: 递归实现&#xff0c;将数组分成两半。分别处理。再合并。 伪代码例如以下&#xff1a; split ( A[], l, r) {if ( r - l < 2) return;m (r l) / 2;split ( A, l, m); //split A[l…m-1]split ( A, m, r); //s…

qcap 教程_高通平台抓取ramdump及使用qcap解析,ramdumpqcap

高通平台抓取ramdump及使用qcap解析&#xff0c;ramdumpqcap高通死机或者查找休眠问题可以通过ramdump来分析&#xff0c;具体步骤先确认下内核配置了CONFIG_MSM_DLOAD_MODE&#xff0c;并确认download_mode为1grep -rin CONFIG_MSM_DLOAD_MODE out/target/product/xxxxx/obj/K…

STM32学习笔记(五)——通用定时器计数延时

STM32定时器概述 STM32F40x系列总共最多有14个定时器&#xff0c;定时器分为三类&#xff1a;基本定时器、通用定时器和高级定时器。它们的都是通过计数来达到定时的目的&#xff0c;和51的定时器差不多&#xff0c;基本原理都是一样的&#xff0c;就是功能多了一些&#xff0c…

win10user文件夹迁移_Win10用户文件如何从系统盘转到其他盘

系统盘什么?就是放置Windows系统的硬盘。安装系统放在系统盘里&#xff0c;本身已经占了很大空间&#xff0c;可是用户文件也放在系统盘里。Win10如何把用户文件转移到非系统盘?下面就Win10消费者预览版Build9926为例&#xff0c;与大家分享一下把Win10用户文件移动到非系统盘…

第十九讲:职责链模式

public class CarBodyHandler extends CarHandler{Overridepublic void HandlerCar() {// TODO Auto-generated method stubSystem.out.println("组装车身");}} public abstract class CarHandler {public abstract void HandlerCar(); } public class CarHeadHandle…

十道解分式方程及答案_100道八年级分式方程及答案.

天.一辈子也打不完哪.再问&#xff1a; 50到吧再答&#xff1a; http://zhidao.baidu.com/question/238264424.html 个网址里面有一些&#xff0c;因为有字数限制&#xff0c;我不好发题目给你&#xff0c;所以你自己去看看吧。 例 解方程&#xff1a; (1)2xxx31; (2)15x215 x1…

四阶行列式直接展开_四阶行列式的完全展开式共有多少项

展开全部 共24项。 1.将该行列式前三列重复书写在该行列式的右边,可在前四列中作出两条对角线,然e5a48de588b662616964757a686964616f31333365663463后在此七列中作出相应的平行线,可得(图表一) 2.作乘积关系,可得如下八项: a11a22a33a44,a12a23a34a41,a13a24a31a42,a14a2…

c++ 返回智能指针_C++核心指南(17) I.11 禁止使用指针(T*)或引用(T)来转移所有权...

I.11: 永远不要使用原始指针(T*)或引用(T&)来转移所有权原因如果对调用者或被调用者是否拥有对象有任何疑问&#xff0c;就会发生泄漏或过早析构。示例考虑:X* compute(args) // 不要这样做 { X* res new X{}; // ... return res; }谁来删除返回的X&#xff1f;当compute返…

for-each循环

for-each循环又叫for增强循环&#xff0c;不需要下标就可以顺序的便历整个数组例如 package cn.hsop.fentian;public class Forxunhuan {public static void main(String[] args) {int[] num { 5, 8, 3, 6 };//定义数组int maxnum[0] ;//假设最大值//遍历数组for (int a : num…