解题思路:
注意事项:
参考代码:
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<bits/stdc++.h> using namespace std; int n=1; int intercept[1001],m[1001]; int main() { while(scanf("%d",&m[n])==1) { // if(m[n]==0) break; n++; } int temp=-1,chaju=INT_MAX; int flag=0,k=1; intercept[1]=m[1]; for(int i=2;i<=n;i++) { flag=0; for(int j=1;j<=k;j++) { int t; t=intercept[j]-m[i]; //cout<<t<<' '; if(intercept[j]>m[i]&&t<chaju) { //cout<<"执行次数"<<endl; temp=j;flag=1;chaju=t; } } if(flag==1) {intercept[temp]=m[i];} else if(flag==0){k+=1;intercept[k]=m[i];} chaju=INT_MAX; // cout<<intercept[k]<<endl;; } cout<<k<<endl; return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:569 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:672 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:736 |
九宫重排 (C++代码)浏览:1333 |
【出圈】 (C语言代码)浏览:557 |
字符串对比 (C语言代码)浏览:1403 |
输出正反三角形 (C语言代码)浏览:790 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:503 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:326 |