zoukankan      html  css  js  c++  java
  • CF 188 div2 解题报告

    本来是想昨天做的了,不过室友不小心把网断了,而且今天要四级 ,就放到今天来做了

    第一题:大水题:

    // File Name: a.c
    // Author: darkdream
    // Created Time: 2013年06月15日 星期六 12时04分25秒
    
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    
    int main(){
    
       //freopen("/home/plac/problem/input.txt","r",stdin);
       //freopen("/home/plac/problem/output.txt","w",stdout);
       long long  n , m;
       scanf("%lld %lld",&n,&m);
       long long  t = ceil(n/2.0);
       if(m <= t)
       {
         printf("%I64d\n",2*m-1);
       }
       else
       {
         printf("%I64d\n",2*(m-t));
       }
    return 0 ;
    }
    View Code

    第二题:大水题,strstr水过的;

    // File Name: b.c
    // Author: darkdream
    // Created Time: 2013年06月15日 星期六 12时15分47秒
    
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    char str[1000007];
    int a[1000007];
    int b[1000007];
    
    int main(){
    
       //freopen("/home/plac/problem/input.txt","r",stdin);
       //freopen("/home/plac/problem/output.txt","w",stdout);
       scanf("%s",str);
       char *p;
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       p = str;
       int t = 0 ;
       long long int sum = 0 ;
       while(strstr(p,"heavy")!=NULL)
       {
           t++;
           a[t] = strstr(p,"heavy") - str ;
           p = strstr(p,"heavy")+ 5;
           
       }
       int k = 0 ;
       p = str;
       while(strstr(p,"metal") != NULL)
       {
           k++;
           b[k] = strstr(p,"metal") - str ;
           p = strstr(p,"metal") + 5;
       }
       int next = 1; 
       for(int i = 1; i<= t; )
       {
          if(next == k +1) 
              break;
          if(a[i] < b[next])
          {
              sum += k - next +1;
              i ++ ;
          }
          else
             next  ++;
       }
       printf("%I64d\n",sum);
    return 0 ;
    }
    View Code

    第三题:

    题意:给你三个数 x , y  ,m  你要使 x >= m 或者 y >=m , 你可以进行以下操作 ,把 x + y 替换 x 或者 y  , 问你最少要进行多少次操作才能使得其中一个数 大于等于 m;

    解题思路:

    设   x 始终大于 y;

    如果 y <= 0  , x <= 0  , m >  x 肯定不可能如果 y <= 0 ,  x > 0  , 则简化操作(把y快速变成正数,不然会超时)

    然后在进行操作(用 x+y 替换掉 y);

    解题代码:

    // File Name: b.c
    // Author: darkdream
    // Created Time: 2013年06月15日 星期六 12时15分47秒
    
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    char str[1000007];
    int a[1000007];
    int b[1000007];
    
    int main(){
    
       //freopen("/home/plac/problem/input.txt","r",stdin);
       //freopen("/home/plac/problem/output.txt","w",stdout);
       scanf("%s",str);
       char *p;
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       p = str;
       int t = 0 ;
       long long int sum = 0 ;
       while(strstr(p,"heavy")!=NULL)
       {
           t++;
           a[t] = strstr(p,"heavy") - str ;
           p = strstr(p,"heavy")+ 5;
           
       }
       int k = 0 ;
       p = str;
       while(strstr(p,"metal") != NULL)
       {
           k++;
           b[k] = strstr(p,"metal") - str ;
           p = strstr(p,"metal") + 5;
       }
       int next = 1; 
       for(int i = 1; i<= t; )
       {
          if(next == k +1) 
              break;
          if(a[i] < b[next])
          {
              sum += k - next +1;
              i ++ ;
          }
          else
             next  ++;
       }
       printf("%I64d\n",sum);
    return 0 ;
    }
    View Code

    第四题:

    题意:一个二维平面坐标系,把n只蚂蚁放在 (0.0)点,如果一个点的蚂蚁大于 4 个的话 ,那么就有 4个蚂蚁朝 4个方向走到达 相邻点  最后给出你t个询问,问你某个坐标有多少个蚂蚁;

    解题思路:广搜,模拟,因为蚂蚁数量不大(1,30000),蚂蚁不会跑到多远(半径为64的圆),但是不能一个一个的去模拟,一个格子要走就要全部走出去,这样才会降低时间复杂度,在广搜的时候还要注意如果一个点有多个上一状态,要去重,就可以算出那些点有几个蚂蚁(询问坐标太远的肯定为0);

    解题代码:

    // File Name: d.c
    // Author: darkdream
    // Created Time: 2013年06月15日 星期六 14时26分25秒
    
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    int a[1000][1000];
    int visit[1000][1000];
    int xdd[]= {0,0,1,-1};
    int ydd[] = {1,-1,0,0};
    struct node
    {
        int x, y ;
    }list[1000005];
    
    int main(){
    
        //freopen("/home/plac/problem/input.txt","r",stdin);
        //freopen("/home/plac/problem/output.txt","w",stdout);
        int n; 
        while(scanf("%d",&n)!= EOF)
        {
            memset(a,0,sizeof(a));
            memset(list,0,sizeof(list));
            memset(visit,-1,sizeof(visit));
            a[500][500] = n;
    
            int low = 1 ; int high = 2;
            list[1].x = 500;
            list[1].y = 500;
            visit[500][500] = n;
            while(low !=  high)
            { int temp;
                if(a[list[low].x][list[low].y] >= 4)
                {
                    temp = (a[list[low].x][list[low].y] - a[list[low].x][list[low].y]%4)/4;
                    a[list[low].x][list[low].y] = a[list[low].x][list[low].y]%4;
                    visit[list[low].x][list[low].y] = -1;
                }
                else
                {
                    low = (low+1) % 1000000;
                    continue;
                }
                for(int i = 0;i < 4; i++)
                {
                    int tx = list[low].x + xdd[i];
                    int ty = list[low].y + ydd[i];
                    a[tx][ty] += temp;
                    if(a[tx][ty] >= 4)
                    {   
                        if(visit[tx][ty] == -1)
                        {
                        list[high].x = tx;
                        list[high].y = ty ;
                        visit[tx][ty] = high;
                        high = (high+1) % 1000000;
                    
                        }
                    }
                }
                low = (low+1)%1000000;
            }
          int t ,k,b  ;
          scanf("%d",&t);
          while(t--)
          {
            scanf("%d %d", &k, &b);
            if(abs(k) > 500  || abs(b) > 500)
                printf("0\n");
            else
            {
              printf("%d\n",a[500+k][500+b]);
            }
          }
        }
        return 0 ;
    }
    View Code

     最后一题不会做。。。囧

    没有梦想,何谈远方
  • 相关阅读:
    codevs1080线段树练习
    NOIP2015 子串
    codevs1204 寻找子串位置
    字符串匹配的KMP算法
    TYVJ1460 旅行
    基础
    搜索
    二叉排序树
    二叉树
    poj
  • 原文地址:https://www.cnblogs.com/zyue/p/3137713.html
Copyright © 2011-2022 走看看