日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

uva 1623——Enter The Dragon

發布時間:2023/11/30 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uva 1623——Enter The Dragon 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:有n個裝滿水的湖,可以預知將來m天下雨情況,每次下滿一個湖,或者不下,不下雨的時候可以讓某個湖變干,問是否存在一種方案使得每次下雨之前湖總是干的。


思路:貪心。什么時候下雨,就什么時候在下雨之前把湖變干。實際上就是找該湖上一次滿后的第一個不下雨的日子來把它變干。


code:

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <sstream> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <map> #include <set> #include <bitset>using namespace std;typedef long long ll; typedef unsigned long long ull; typedef long double ld;const int INF=0x3fffffff; const int inf=-INF; const int N=1000005; const int M=2005; const int mod=1000000007; const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x)) #define cpy(x,a) memcpy(x,a,sizeof(a)) #define fr(i,s,n) for (int i=s;i<=n;i++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 #define middle int m=(r+l)>>1 #define lowbit(x) (x&-x) #define pii pair<int,int> #define mk make_pair #define IN freopen("in.txt","r",stdin); #define OUT freopen("out.txt","w",stdout);int v[N],la[N],s[N]; set<int>ep; set<int>::iterator p; int main() {int T,n,m,f;scanf("%d",&T);while (T--){cls(s,0);cls(la,0);f=0;ep.clear();scanf("%d %d",&n,&m);fr(i,0,m-1){scanf("%d",&v[i]);if (f) continue;if (!v[i]) ep.insert(i);//cout<<i<<endl;else{p=ep.lower_bound(la[v[i]]);if (p==ep.end()) f=1;else{//cout<<*p<<endl;s[*p]=v[i];la[v[i]]=i;ep.erase(p);}}}if (f) puts("NO");else{puts("YES");fr(i,0,m-1){if (!v[i]) printf("%d ",s[i]);}puts("");}} }


總結

以上是生活随笔為你收集整理的uva 1623——Enter The Dragon的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。