codeforce #387 D. Winter Is Coming
来源:互联网 发布:男科网络预约挂号 编辑:程序博客网 时间:2024/05/16 01:45
题意:一个冬季轮胎 一个夏季轮胎 夏季轮胎只能在温度>=0的天气使用 但可以用无限次 冬季轮胎可以在任何温度下使用 但有天数和数量限制, 问最少换多少次轮胎。
下面给出代码 :
/* _...---.._ ,' ~~"--.. / ~"-._ / ~-. / . `-. \ -.\ `-. \ ~-. `-. ,-~~\ ~. / \ `.. \ `.| \ .| \ \ . `. \ \ \ ` `. \ ` \. \ ` \`. \ . \ -. \ ` -. \ . ` - \ . ` \ ~- \ ` . ~. \ . \ -_ \ ` - \ . | ~. \ ` | \ \ . | \ \ ` | `. \ ` ` \ \ . . `. `. ` : \ `. \ ` \ `. \ . `. `~~-. \ : ` \ \ . . \ : `.\ ` : \ | | . \ . \ | | \ : \ ` | ` . . | |_ . ` `. ` ` | ~.; \ `. . . . . `. ` ` ` `. `._. \ `.\ ` < \ `. | . ` ` : ` | | ` \ ` | | `. | \ : .' |"Are you crying? " ` | \ `_-' | "It's only the rain." : | | | : ;"The rain already stopped."` ; |~-.| : ' "Devils never cry." : \ | ` , ` \` : ' : \` `_/ ` .\ "For we have none. Our enemy shall fall." ` ` \ "As we apprise. To claim our fate." \ | : "Now and forever. " \ .' : "We'll be together." : : "In love and in hate" | .' | : "They will see. We'll fight until eternity. " | ' "Come with me.We'll stand and fight together." | / "Through our strength We'll make a better day. " `_.' "Tomorrow we shall never surrender." sao xin*/#include <bits/stdc++.h>using namespace std;#define LL long long#define INF 0x3f3f3f3#define pi acos(-1)//const LL INF = 1e15;const int maxn=1e3+5;const int maxx=1e5+5;//const double q = (1 + sqrt(5.0)) / 2.0; // 黄金分割数/*std::hex <<16进制 cin>>std::hex>>a>>std::hex>>bcout.setf(ios::uppercase);cout<<std::hex<<c<<endl;//f[i]=(i-1)*(f[i-1]+f[i-2]); 错排priority_queue<int,vector<int>,greater<int> >que3;//注意“>>”会被认为错误,priority_queue<int,vector<int>,less<int> >que4;////最大值优先//str tmp vis val cnt 2486struct point { int id; int ed; bool operator < (const point &a) const { return ed > a.ed;//结束时间早的优先级高 }} p;*/int n,m,ans,sum,last;int a[300001];multiset <int> q;int main(){scanf("%d%d",&n,&m);for (int i=1;i<=n;i++) scanf("%d",&a[i]);int t;for (t=1;t<=n&&a[t]>=0;t++); last=-1;//夏季轮胎可以用多少天while (t<=n){int tmp=0; ans++;//cout<<ans<<endl;if (a[t]<0){for (;t<=n&&a[t]<0;t++) tmp++;//冬季轮胎m-=tmp;} else {for (;t<=n&&a[t]>=0;t++) tmp++;//夏季轮胎if (t>n) last=tmp;else q.insert(tmp);}}multiset <int> :: iterator it;if (m<0) printf("-1\n");else {while (!q.empty())//当set里面还有元素的时候进去判断你使用的夏天的轮胎的天数是否在冬季能使用的天数之内{if (*q.begin()<=m){ans-=2; m-=*q.begin();//ans是存的换轮胎的次数 如果能就就减少两次换轮胎次数 然后冬季轮胎寿命减少那么多次 q.erase(q.begin());//然后循环到不能减少换胎次数} else break;}if (last!=-1&&last<=m) ans--;//last记录的最后一程 最后可能为夏天轮胎能走的一程 然后如果那一程的天数小于轮胎寿命 那么就少换一次轮胎直接开过去printf("%d\n",ans);}return 0;}
0 0
- codeforce #387 D. Winter Is Coming
- Codeforces Round #387 (Div. 2) D. Winter Is Coming
- Codeforces Round #387 (Div. 2) D. Winter Is Coming
- 【23.26%】【codeforces 747D】Winter Is Coming
- codeforces 747D Winter Is Coming
- Problem 747D - Winter Is Coming
- 贪心 CodeForces - 747D Winter Is Coming
- Codeforces Round #387 (Div. 2)A~D A Display Size D Winter Is Coming
- Codeforces Round #387 (Div. 2) D && coedeforces 744 D. Winter Is Coming(贪心)
- Winter Is Coming(CF #387 Div. 2)
- winter is coming
- The Winter Is Coming
- Winter Is Coming CodeForces
- Codeforces Round #387 (Div. 2)D. Winter Is Coming(优先队列)
- Codeforces Round #387(Div. 2)D. Winter Is Coming【思维+dp】
- Codeforces Round #387 (Div. 2)D. Winter Is Coming(复杂贪心)
- codeforces 747 D. Winter Is Coming (贪心)
- Winter Is Coming(贪心)
- 2015-2016年iOS开发经验总结
- iOS相册权限、相机权限、麦克风权限
- bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群
- 文章标题【树】哈夫曼树
- 带你快速玩转canvas(7)保存画笔状态和恢复画笔状态
- codeforce #387 D. Winter Is Coming
- 第3章 基本概念(4)操作符:一元操作符......
- 【OpenSource】【图片加载】Google 推荐的图片加载开源框架 Glide
- 给samba的文件服务器启用回收站功能
- Android 技术之Glide和Picasso
- tomcat下配置https环境(windows环境)
- OAuth 2.0 授权原理
- 算法篇-7-贪心算法-Huffman编码&Dijkstra单源最短路径&Kruskal最小生成树
- Maven依赖之后Dubbo找不到依赖的facade