usaco1.1.4 Broken Necklace破碎的项链
来源:互联网 发布:云计算产业园 编辑:程序博客网 时间:2024/05/07 14:43
usaco1.1.4 beads
Broken Necklace破碎的项链
仍然是模拟,但要注意这个项链是环状的。有一种比较先进的办法是把这个项链载入两次,这样就可以从头到尾遍历了。注意白色的珠子不能作为起点。
我的程序没有用上面的方法,直接遍历到最后在返回开头。
我的程序没有用上面的方法,直接遍历到最后在返回开头。
/*ID: wsc5001LANG: CTASK: beads*/#include<stdio.h>#include <stdlib.h>char ch[351];int n;int zhaoqian(int st){ char goon; int i=0,timess=0; while(st+i<n && (ch[st+i]=='w') ) {i++;} while(st+i>=n && (ch[st+i-n]=='w')) {i++;} goon = ch[st+i]; i=0; while(st+i<n && (ch[st+i]==goon||ch[st+i]=='w')) {timess++; i++;} while(st+i>=n && (ch[st+i-n]==goon||ch[st+i-n]=='w')) {timess++; i++;} return timess;}int zhaohou(int st){ char goon; int i=0,timess=0; while(st-i>=0 && (ch[st-i]=='w')) {i++;} while(st-i<0 && (ch[st-i+n]=='w')) {i++;} goon = ch[st-i]; i=0; while( st-i>=0 && (ch[st-i]==goon||ch[st-i]=='w') ) {timess++; i++;} while(st-i<0 && (ch[st-i+n]==goon||ch[st-i+n]=='w')) {timess++; i++;} return timess;}int main(){ FILE *fin,*fout; fin=fopen("beads.in","r"); fout=fopen("beads.out","w"); int nfront=0,nback=0,max=0; int i,j,flag; //读入 fscanf(fin,"%d%s",&n,ch); flag=0; for (i=0;i<n;i++) if(ch[i]!=ch[0]&&ch[i]!='w') {flag=1;break;} if (flag==0) {fprintf(fout,"%d\n",n);} else { for (i=0;i<n;i++) { nfront=zhaoqian(i+1); nback=zhaohou(i); if (nfront+nback>max) max=nfront+nback; if (max>n) max=n; } fprintf(fout,"%d\n",max); } fclose(fin); fclose(fout); //system("pause");}
- usaco1.1.4 Broken Necklace破碎的项链
- USACO1.1.4 Broken Necklace(破碎的项链)
- USACO1.1.4 Broken Necklace 破碎的项链
- 【USACO1.1_4】★Broken Necklace 破碎的项链
- Broken Necklace破碎的项链
- Broken Necklace破碎的项链
- [USACO1.1.4]坏掉的项链Broken Necklace
- Broken Necklace-----破碎的项链----USACO---C1S1
- Usaco 1.1.4 破碎的项链(Broken Necklace)
- 【USACO题库】1.1.4 Broken Necklace破碎的项链
- 【USACO题库】1.1.4 Broken Necklace破碎的项链
- 【USACO题库】1.1.4 Broken Necklace破碎的项链
- |洛谷|模拟|P1203 [USACO1.1]坏掉的项链Broken Necklace
- 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- P1203 [USACO1.1]坏掉的项链Broken Necklace
- 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- 【P1203】 【USACO1.1】坏掉的项链Broken Necklace
- CSDN“泄密门”两名黑客落网,与实名制无关
- 过滤器[登录+编码]filter在程序中的使用
- 支付宝打造新支付架构:对外开放 平台化发展
- strcmp与strncmp区别
- 查看进程占用内存
- usaco1.1.4 Broken Necklace破碎的项链
- 团购倒计时特效代码 带天数日期及分时秒
- 用marquee和div+js实现首尾相连循环滚动
- Using Simple Technique to Improve Your Lighting Effect
- nginx多进程模型之热代码平滑升级
- Android-一些关于代码优化的事儿
- usaco 1.2.1 Milking Cows 挤牛奶
- IT项目需求获取和管理
- 在ubuntu11.10中安装chrome浏览器