【google code jam Qualification Round 2017】【Oversized Pancake Flipper】【贪心】
来源:互联网 发布:suse linux 扩磁盘 编辑:程序博客网 时间:2024/05/20 00:39
题目大意
给你一列01串,每次可改变连续k个的状态,求全部变成1的最小代价。
解题思路
从左到右扫,要变就变,判断最后可不可行。
code
#include<set>#include<cmath>#include<cstdio>#include<cstring>#include<algorithm>#define LF double#define LL long long#define ULL unsigned long long#define min(a,b) ((a<b)?a:b)#define max(a,b) ((a>b)?a:b)#define fo(i,j,k) for(int i=j;i<=k;i++)#define fd(i,j,k) for(int i=j;i>=k;i--)#define fr(i,j) for(int i=Begin[j];i;i=Next[i])using namespace std;int const ml=1000+9,Inf=1e9;int t,n,a[ml];int main(){ freopen("d.in","r",stdin); freopen("d.out","w",stdout); scanf("%d",&t); fo(cas,1,t){ char ch=getchar();a[0]=0; while((ch!='-')&&(ch!='+'))ch=getchar(); while((ch=='-')||(ch=='+'))a[++a[0]]=(ch=='+'),ch=getchar(); scanf("%d",&n);int ans=0; fo(i,1,a[0]-n+1)if(!a[i]){ ans++; fo(j,i,i+n-1)a[j]=1-a[j]; } int ok=1; fo(i,1,a[0])if(!a[i]){ok=0;break;} if(ok)printf("Case #%d: %d\n",cas,ans); else printf("Case #%d: IMPOSSIBLE\n",cas); } return 0;}
0 0
- 【google code jam Qualification Round 2017】【Oversized Pancake Flipper】【贪心】
- Code Jam 2017 Qualification Round Problem A. Oversized Pancake Flipper
- 【google code jam Qualification Round 2017】【Tidy Numbers】【搜索】
- 【google code jam Qualification Round 2017】【Bathroom Stalls】
- 2009 Google Code Jam Qualification Round 题解
- Google Code Jam 2011 Qualification Round ProblemA
- Google Code Jam 2012 Qualification Round
- Google Code Jam Qualification Round 2012
- Reverse-GOOGLE CODE JAM AFICA 2010 Qualification Round
- T9 Spelling-GOOGLE CODE JAM AFICA 2010 Qualification Round
- Store Credit-GOOGLE CODE JAM AFICA 2010 Qualification Round
- ACM-GOOGLE CODE JAM 2011 Qualification Round 2011(总结)
- Google Code Jam 2010 Qualification Round 2012 Problem B && C
- Google Code Jam 2014 Qualification Round 2014 A B D
- Google Code Jam 2014-Qualification Round-Problem C. Minesweeper Master
- Google Code Jam 2014 Qualification Round:Problem A. Magic Trick
- Google Code Jam 2014 Qualification Round:D. Deceitful War
- Google Code jam Qualification Round 2015 解题报告
- 区块链 Hyperledger
- Python学习笔记(五)
- ORACLE 10g关于全局数据库名和SID的简介
- BottomBar有文字的情况
- Windows下编码在Linux系统下中文乱码解决方案
- 【google code jam Qualification Round 2017】【Oversized Pancake Flipper】【贪心】
- Java数组类型的定义和初始化
- 7.Django入门:教程-测试
- 封装一个类:软键盘弹出,将控件整体顶上去
- js 跨域
- 如何在水经注会员中心购买流量下载地图
- vmware 解决"二进制转换与此平台上的长模式不兼容"
- OpenGL Direct3D(DirectX)区别
- 数据结构之链栈