zoukankan      html  css  js  c++  java
  • 经典c程序(0028)---最长假期

        /**************************************************************************************     
        * Function     : 最长假期 
        * Create Date  : 2014/05/16   
        * Author       : NTSK13     
        * Email        : beijiwei@qq.com     
        * Copyright    : 欢迎大家和我一起交流学习,转载请保持源文件的完整性。     
        *                任何单位和个人不经本人允许不得用于商业用途     
        * Version      : V0.1                        
                              
        题目: 经典c程序(0028)---最长假期 
         
            有位学生利用100天的假期在一个超市打工,这份工作要求是在100天中按照超市给出的工作日去打工。  
        其中可以有2天的工作日可以换成休息日(但是指定的特勤日不能换成休息日) 
        这位学生想利用其中的休息日到欧洲旅行,为了使旅行的时间尽量长,需要知道将哪2天的工作日换成休息日。 
        请编写一个程序如何将这位学生工作日中的2天换成休息日后使他的旅行时间最长。 
         
        假设这位学生的打工时间是17天,如果以下是他的工作日程表: 
         
          1   0     0     1    0    0   1    0    1    2    0     0    0   2    0    0    0 
        工作 休息 休息    工作 休息 休息 工作 休息 工作 特勤 休息 休息 休息 特勤 休息 休息 休息 
         
        如果按照以下的安排。将第四天和第七天的工作日换成休息日的话,一共可以连续休息7天。 
        (如果将特勤的2天换成休息日的话可以连续休息8天,但是注意: 特勤日是无法换成休息日,只能用工作日调整哦) 
        于是得到下表所示的休息计划: 一共可以连续休息7天 
         
          1   0     0     1          0    0   1           0    1    2    0     0    0   2    0    0    0 
        工作 休息 休息    工作->休息 休息 休息 工作->休息 休息 工作 特勤 休息 休息 休息 特勤 休息 休息 休息 
                           
        [构建 函数] 
        int test_main(int data[100]);  
         
        int data[100] : 100天的工作安排日程表 
        0 = 休息日  
        1 = 工作日  
        2 = 特勤 (无法换成休息日) 
        return : 返回通过调整可以得到的”最长休息日”天数。 
         
        **************************************************************************************/          
        #include<stdio.h>   
        #include <stdio.h>  
        #include <stdlib.h>  
          
        #define SIZE 100  
          
        static int data[SIZE];  
          
        typedef struct method  
        {  
            int x;  
            int y;  
            int len;  
        }Met;  
          
        Met way;  
          
          
        int test(int data[SIZE]);  
          
          
        static void build_data(void)  
        {  
            int c = 0;  
            for ( c = 0; c < SIZE; c++)  
            {  
                data[c] = rand() % 6;  
          
                if (data[c] > 2)   
                    data[c] = 0;  
            }  
        }  
          
          
        void main(void)  
        {  
            int l = 0;  
            for ( l = 0; l < 10; l++)  
            {  
                build_data();  
          
                printf("%d
    
    
    ", test(data));  
            }  
        }  
          
        int test(int data[SIZE])  
        {  
            int i=0,j=0,x=0,y=0,len=0,ret=0;  
            int flag=0,k=0;  
            Met stack[SIZE];  
            //int data[17]={1,0,0,1,0,0,1,0,1,2,0,0,0,2,0,0,0};// for debug  
            while(i<SIZE)  
            {  
                if(data[i]==2)  
                {  
                    i++;  
                    continue;  
                }  
                for(j=i,flag=0,len=0;j<SIZE;j++)  
                {  
                    if(flag==2 && data[j]==1)  
                        break;  
                    if( flag !=2 && data[j]==1)  
                    {  
                        if(flag==0)  
                            x=j;  
                        else  
                            y=j;  
                        flag++;  
                    }  
          
                    if( data[j]==2)  
                    {  
                        flag=0;  
                        break;  
                    }  
                    len++;  
                }  
                stack[k++].x=x;  
                stack[k].y=y;  
                stack[k].len=len;  
                if(ret<len)  
                    ret=len;  
                i++;  
            }  
          
            for(k=0;k<SIZE;k++)  
            {  
                if(stack[k].len==ret)  
                {  
                    printf("先把第%d个工作日变成节假日
    ",stack[k].x);  
                    printf("再把第%d个工作日变成节假日
    ",stack[k].y);  
                    printf("done !!!
    ");  
                    break;  
                }  
            }  
          
            return ret;  
        }  
    
  • 相关阅读:
    BZOJ 1565: [NOI2009]植物大战僵尸
    BZOJ 1617: [Usaco2008 Mar]River Crossing渡河问题
    BZOJ 2820: YY的GCD
    数论模版-欧拉函数、莫比乌斯函数和素数
    BZOJ 2818: Gcd
    BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
    BZOJ 1614: [Usaco2007 Jan]Telephone Lines架设电话线
    BZOJ 1613: [Usaco2007 Jan]Running贝茜的晨练计划
    BZOJ 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛
    Unity5.3.4版本打包APk,安卓识别不了 Application.systemLanguage
  • 原文地址:https://www.cnblogs.com/ntsk13/p/3745530.html
Copyright © 2011-2022 走看看