HDU 1257 最少拦截系统
来源:互联网 发布:安卓新闻客户端源码 编辑:程序博客网 时间:2024/05/17 09:03
//方法一:#include <stdio.h>#define N 1000000int a[N];int main(){ int n,max; while(scanf("%d",&n)==1) { for(int i=0; i<n; i++) scanf("%d",&a[i]); int count=0; for(int i=0; i<n; i++) { if(a[i]==0) continue; else { count++; max=a[i]; for(int j=i+1; j<n; j++) { if((a[j]!=0) && (a[j] <= max)) { max=a[j]; a[j] = 0; } } } } printf("%d\n",count ); } return 0;}//方法二: #include<stdio.h>#include<string.h>int z[1000];int main(){ int m; while(scanf("%d",&m)!=EOF){int i=1;memset(z,0,sizeof(z)); z[0]=30009;int n,j; while(m--) { scanf("%d",&n);for(j=0;j<=i;j++){if(n<=z[j]){z[j]=n;break;}}if(j>i) { i++;z[i]=n; }}printf("%d\n",i);} return 0;}
此题属于贪心。一开始把这道题想的简单化了,以为只是相邻两个数比较就行了,结果总是WS,郁闷了半天。最后经过我多遍读题重要恍然大悟,此题不仅仅只比较相邻两个数就可以了,如题目中给的数据最佳排序应该这样:389 →207 →155 →65,300 →299 →170 →158 。看见这个,你应该懂了吧,话不多说,看一下代码。
- hdu 1257 最少拦截系统
- 最少拦截系统 hdu 1257
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- unity3d Hard Surface Shader 使用方法
- 等值首尾和
- 报警声音并像QQ一样闪烁的对话框
- QT网络编程-TCP
- vim配置文件
- HDU 1257 最少拦截系统
- android animation
- QT网络编程-http
- 通过magento后台的magento connect安装magento extension
- QT网络编程-UDP
- 基于数组的循环队列
- shell脚本:一次读取文件的一行【转】
- 最短路-find the safest road
- 简易的c垃圾收集器