【google code jam Qualification Round 2017】【Oversized Pancake Flipper】【贪心】
2017-04-11 15:49
375 查看
题目大意
给你一列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; }
相关文章推荐
- Google codejam Qualification Round 2015 B 巧妙枚举结果 + 贪心
- 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】
- Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation
- dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes
- Google Code Jam 2011 Qualification Round ProblemA
- [Google Code Jam 2017] Round 2 problem A
- 2009 Google Code Jam Qualification Round 题解
- Google Code Jam 2014 Qualification Round C.Minesweeper Master 和 Microsoft某实习机试试题(快速求组合)
- Google Code Jam 2012 Qualification Round. Problem D. Hall of Mirrors
- Google Code Jam 2017 Round 1B [B-large不会]
- GoogleCodeJam Qualification Round 2014 ABD
- [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
- Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation
- dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes
- Google Code Jam Qualification Round 2015 Problem B. Infinite House of Pancakes
- Google CodeJam Qualification Round 2013
- Google Code Jam Qualification Round 2014 Problem A. Magic Trick 题解
- Code Jam 2017 Qualification Round Problem B. Tidy Numbers