poj3044
来源:互联网 发布:scrollreveal.js实例 编辑:程序博客网 时间:2024/05/17 07:57
扫描一直WA:
#include<iostream>
using namespace std;
long stack[50002];
long x,y;
int main()
{
int n;
long w;
int ans=0,top=-1;
scanf("%ld %ld",&n,&w);
scanf("%ld %ld",&x,&y);
stack[++top]=y;
for(int i=1;i<n;i++)
{
scanf("%ld %ld",&x,&y);
while(stack[top]>y)
{
top--;
ans++;
}
if(stack[top]<y)
{
stack[++top]=y;
}
if(stack[top]==y)
continue;
}
while(top>=0)
{
top--;
ans++;
}
printf("%ld\n",ans);
//system("pause");
return 0;
}
看了别人贪心的代码:
#include<stdio.h>
#include<string.h>
const int N=50009;
bool used[N];
int x[50009];
int y[50009];
int main()
{
int n,w;
while(scanf("%d%d",&n,&w)!=EOF)
{
int i,j;
for(i=1;i<=n;i++)
{
scanf("%d%d",&x[i],&y[i]);
used[i]=0;
}
int add=0;
for(i=n;i>=1;i--)
{
if(y[i]==0)continue;
if(used[i]==1)continue;
for(j=i-1;j>=1;j--)
{
if(y[i]<=y[j])
{
if(y[i]==y[j])
used[j]=1;
}
else{
break;
}
}
add++;
}
printf("%d\n",add);
}
}
- poj3044
- 加密工具
- 内存与链表
- 腾讯MIG刘成敏告别邮件:两年前就有退休的想法
- How To Show Line Numbers In vi / vim Text Editor
- Nginx正向代理
- poj3044
- BIT1021 Pascal's Travels
- 《深入剖析Android系统》第9章RIL补充配图
- 开发感想
- linux 下C函数部分
- org.apache.struts2.rest.DefaultHttpHeaders cannot be cast to java.lang.String
- 网页游戏入门教程
- goagent address already in use
- 自动定时备份sqlserver数据库的方法