HDU2019JAVA
数列有序!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 70953 Accepted Submission(s):
30066
1 2 4
0 0
import java.util.*;
class Main{
public static void main(String args[])
{
Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{
int n=cin.nextInt();
int m=cin.nextInt();
if(n==0&&m==0)
break;
int []a=new int [n+1];
int flag=0;
for(int i=0;i<n+1;i++)
{a[i]=cin.nextInt();
if(a[i]>m&&(flag==0))
{a[i+1]=a[i];
a[i]=m;
flag=1;
i++;}
}
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
System.out.println(a[n]);
}
}
}
这采用的是一个一个输入再进行比较。减少了循环的次数;
HDU2019JAVA的更多相关文章
随机推荐
- uva 1396 - Most Distant Point from the Sea
半平面的交,二分的方法: #include<cstdio> #include<algorithm> #include<cmath> #define eps 1e-6 ...
- 在PYTHON中,用cx_Oracle连接ORACLE数据库简单示例
一,在安装的时候,参数有点不一样: python setup.py build install 二,连接数据库,有两种方式,DSN和TNSNAMES方式: #dsn = orcl.makedsn(se ...
- 【SPOJ 2319】 BIGSEQ - Sequence (数位DP+高精度)
BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need ...
- Javascript 取小数点后面N位
用Javascript取float型小数点后两位,例22.127456取成22.13,如何做? 1. 最笨的办法....... [我就怎么干的.........] 1function get() 2{ ...
- [cocos2d demo]认字小游戏
2013.9.5更新第二版 游戏分三个场景,分别为主场景,加载场景以及游戏场景,游戏场景分为背景层,逻辑层以及UI层 1.背景:旋转太阳,移动波浪,漂浮的云 2.UI层:随机生成字附带在帆船上移动,当 ...
- css全局设置
/***** 全局设置 *****/ body,h1,h2,h3,h4,h5,h6,p,form,ul,ol,li,dt,dl,dd,th,td,label,bottom,input,textar ...
- 【HDOJ】2149 Public Sale
看Discuss说是博弈论,没学到这个分类.不过仔细想了想,发现.如果m<=n,那么可能结果为m,m+1...n.否则,如果m%(n+1) == 0,那么无论如何都会输,因为无论先报价什么数,如 ...
- USACO3.44Raucous Rockers
USACO挂了一小时..我坚持不懈的等..终于打开了 把3章最后一题交了 可以安心的睡去了 之前题意没看清楚 不知道要有序 写了一状压 结果TLE了 再优化也TLE 后来想写状态转移时发现 它必须有 ...
- java httpclient post 文件到server
public void sendFileToServer (String url, File logFiles) { HttpURLConnection connection = nul ...
- SQL Server 字段状态判断语句
selct newName=case when 条件 then '否' else '是' end from tableName