zoukankan      html  css  js  c++  java
  • HDU 3788 ZOJ问题

    http://acm.hdu.edu.cn/showproblem.php?pid=3788

    上HDU看到滚动条‘浙大研究生复试上机考试’最近热议的话题是考研的分数下来了。想直接找工作的我,也在犹豫的边缘,挑了了道题做了一下。

    代码写的挫死了..o(╯□╰)o
    1. zoj ac
    2.xxxzojxxx zoj左右两边的o的数量一样多
    3.azbojac 其中它是由xxzojxx一次递归而来的.假设为ozojo(a=1, b=1, c=1)递归而来的,那么一次是ozojo -->ozoojoo --> ozooojooo
    可以发现numa是不变的。numb每次+1,那么变换次数为numb-1。因此要满足2.条可以推出,numc-(numb-1)*numa==numa --> numc==numa*numb;

    代码如下:

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char ch[1005];
        int i, len, numa, numb, numc, plaz, plaj;
        while(gets(ch))
        {
            int flag=1;
            len=strlen(ch);
            plaz=-1, plaj=-1;
            for(i=0; i<len; i++)
                if(ch[i]=='z')
                {  
                    plaz=i;
                    break;
                }
            for(i=0; i<len; i++)
                if(ch[i]=='j')
                {
                    plaj=i;
                    break;
                }
            if(plaz==-1||plaj==-1)
                flag=0;
            if(flag==0)
            {
                printf("Wrong Answer\n");
                continue;
            }
            numa=0, numb=0, numc=0;
            for(i=0; i<plaz; i++)
            {
                if(ch[i]!='o')
                {
                    flag=0;
                    break;
                }
                numa++;
            }
            for(i=plaz+1; i<plaj; i++)
            {
                if(ch[i]!='o')
                {
                    flag=0;
                    break;
                }
                numb++;
            }
            for(i=plaj+1; i<len; i++)
            {
                if(ch[i]!='o')
                {
                    flag=0;
                    break;
                }
                numc++;
            }
            if(flag==0)
            {
                printf("Wrong Answer\n");
                continue;
            }
            if(plaj-plaz>1)
                {
                   if(numc==numa*numb)  
                       printf("Accepted\n");
                    else
                        printf("Wrong Answer\n");
                }
                else
                    printf("Wrong Answer\n");
        }
        return 0;
    }
    

      

  • 相关阅读:
    Best Practices for Background Jobs_3 Managing Device Awake State之电源锁、Alarm、WakefulBroadcastReceiver
    一种扩大View点击范围的方法
    IntentService
    DNS
    GPU硬件加速相关
    SOA 面向服务的体系结构
    android APK 文件的生成过程
    PHP简介
    代码安装apk文件
    View 的 focus 和 selected 状态, TabContainer实现
  • 原文地址:https://www.cnblogs.com/Hilda/p/2923469.html
Copyright © 2011-2022 走看看