hdu 5233 Gunner II 离散化
来源:互联网 发布:java native的用法 编辑:程序博客网 时间:2024/05/22 10:53
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5233
题意:
有n只鸟,还有n棵树。第i只鸟站在第i棵树的顶端。这些树从左到右排成一条直线。每一棵树都有它的高度。Jack站在最左边那棵树的左边。当Jack在高度为H的地方向右发射一棵子弹时,站在高度为H的树上且离Jack最近的鸟儿就会落下来。 Jack会射击多次,他想知道每次射击哪只鸟儿会落下来。
题解:
离散化
代码:
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define MS(a) memset(a,0,sizeof(a))#define MP make_pair#define PB push_backconst int INF = 0x3f3f3f3f;const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//////////////////////////////////////////////////////////////////////////const int maxn = 2e5+10;struct node{ int x,id;}h[maxn];vector<int> k,dp[maxn];map<int,int> H;int q[maxn],cnt[maxn];void init(){ MS(h); MS(q); MS(cnt); H.clear(); k.clear(); for(int i=0; i<maxn; i++) dp[i].clear();}int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ init(); for(int i=0; i<n; i++){ h[i].x = read(); h[i].id = i+1; k.push_back(h[i].x); } for(int i=0; i<m; i++){ q[i] = read(); k.push_back(q[i]); } sort(k.begin(),k.end()); k.erase(unique(k.begin(),k.end()),k.end()); for(int i=0; i<(int)k.size(); i++){ H[k[i]] = i; } for(int i=0; i<n; i++) dp[H[h[i].x]].push_back(h[i].id); for(int i=0; i<m; i++){ if(cnt[H[q[i]]] >= (int)dp[H[q[i]]].size()) cout << -1 << endl; else{ cout << dp[H[q[i]]][cnt[H[q[i]]]] << endl; cnt[H[q[i]]]++; } } } return 0;}
0 0
- hdu 5233 Gunner II (map离散化)
- hdu 5233 Gunner II 离散化
- hdu 5233 Gunner II(数据离散化存储)
- hdu 5233- Gunner II(BestCoder Round #42)离散化
- hdu 5233 Gunner II
- hdu 5233 Gunner II
- hdu 5233 Gunner II
- HDU ACM 5233 Gunner II
- HDU 5233 Gunner II (二分)
- hdu 5233 Gunner II 【set+map】
- hdu 5233 Gunner II【STL应用】【水题】
- hdu 5233 Gunner II (容器)
- HDU 5233 Gunner II 数据结构map+vector
- HDU5233 Gunner II 离散化的各种方法
- 【BestCoder】 HDOJ 5233 Gunner II
- hdoj 5233 Gunner II 【二分】
- HDOJ 5233 Gunner II【二分&&邻接表】
- hdu5233 Gunner II
- [java] 快速排序
- Facade
- mysql5.7 忘记root密码了如何重新设置
- 西瓜理发记(一)
- C#的自悟
- hdu 5233 Gunner II 离散化
- 极光推送(基础篇)
- struts-2.3.31和struts-2.5.10引入jar以及配置web.xml和struts.xml
- Thread-synchronized同步 -火车票实例
- jdk环境变量配置
- C#的转换方式
- 学习JavaScript闭包
- 20.Spark上下文构建以及模拟数据生成
- Spring面试,IoC和AOP的理解