POJ-3276 Face The Right Way
来源:互联网 发布:JavaScript什么是闭包 编辑:程序博客网 时间:2024/04/30 10:33
不会编程实现。T,T
我发现自己不会组织代码之间的关系。
是否满足条件?M与m的对比。
无法全部翻转的条件怎么表示? 返回-1
对于数学关系的表达?看sum的表示。
书上的代码:
const int maxn=5050;int N;int dir[maxn];int f[maxn];int calc(int K){ clr(f); int res=0; int sum=0; for(int i=0;i<=N-K;i++) { if((dir[i]+sum)%2!=0) { res++; f[i]=1; } sum+=f[i]; if(i-K+1>=0) sum-=f[i-K+1]; } for(int i=N-K+1;i<N;i++) { if((dir[i]+sum)%2!=0) return -1; if(i-K+1>=0) sum-=f[i-K+1]; } return res;}int main(){ scanf("%d",&N); char s; for(int i=0;i<N;i++) { scanf(" %c",&s); dir[i]=(s=='F'?0:1); } int K=1,M=N; for(int k=1;k<=N;k++) { int m=calc(k); if(m>=0&&M>m) { M=m; K=k; } } printf("%d %d\n",K,M); return 0;}
参考博客:点击打开链接
博客上面的思路:相对不变。。。脑洞能力。。。。。,并不能理解T,T
0 0
- poj 3276 Face The Right Way
- poj 3276 Face The Right Way
- POJ-3276-Face The Right Way
- Poj 3276 Face The Right Way
- poj 3276 Face The Right Way
- POJ 3276 Face The Right Way
- POJ 3276 Face The Right Way
- poj 3276 Face The Right Way
- Face The Right Way POJ 3276
- poj 3276 Face The Right Way
- POJ 3276 Face The Right Way
- POJ 3276 Face The Right Way
- POJ-3276 Face The Right Way
- POJ 3276 Face The Right Way【枚举】
- POJ-3276 Face The Right Way
- POJ 3276 Face The Right Way 模拟
- poj 3276 Face The Right Way@
- poj 3276 Face the right way
- poj-3185 The Water Bowls
- Mysql 里CHAR和VARCHAR的最大长度及一些注意事项
- 整数变换问题和N皇后问题解析(C语言)
- 七、Linux/UNIX操作命令积累【touch、chkconfig】
- getopt:命令行选项、参数处理
- POJ-3276 Face The Right Way
- android常见的库文件
- git学习推荐
- Angularjs1.x 中的 constant, value
- MySql安装种种
- 电池状态获取(UIDevice、battery、UIDeviceBattery)
- 操作系统与网络实现 之十三
- Selenium+AdroidDriver测试android wap页
- 浅谈三层