【LDU】2017级新生赛

A - Theatre Square 

http://codeforces.com/problemset/problem/1/A

Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.

What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

Input

The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

Output

Write the needed number of flagstones.

Examples
input
6 6 4
output
4

#include<stdio.h>
int main()
{
    long long len1,len2;
    long long n,m,a;
    scanf("%lld%lld%lld",&n,&m,&a);
    len1=n%a?n/a+1:n/a;
    len2=m%a?m/a+1:m/a;
    printf("%lld",len1*len2);
    return 0;
}

B - 赋值问题 

http://acm.fzu.edu.cn/problem.php?pid=1055

 Problem Description

在很多程序设计语言中,忘记给变量赋初值的错误常令人头疼。请编程求出含N(0≤N≤100)行的程序段运行以后有哪些变量中有确定的值。 在下面的问题中,最开始仅有变量a中有确定的值。变量为单个小写字母,每行恰好有三个字符,中间一个是赋值运算符'='。

 Input

输入有多组数据,每组数据的第一行有一个整数N,表示程序段的行数。以下N行,每行3个字符,为一条语句。最后一组数据N=-1表示输入结束,不需要处理。

 Output

对每一组数据输出一行结果,按字母表顺序给出所有有确定值的变量名。如果没有变量有确定的值,输出none。

 Sample Input

4
b=a
c=d
d=b
e=f
-1

 Sample Output

a b d


#include<stdio.h>
#include<string.h>
int main()
{
     int n;
     while(scanf("%d",&n))
     {
         if(n==-1)
            break;
         char x,y;
         int a[27]={1},i,flag=0;
         for(i=0;i<n;i++)
         {
             getchar();
             scanf("%c=%c",&x,&y);
             a[x-'a']=a[y-'a'];
         }
         for(i=0;i<27;i++)
         {
            if(a[i]!=0)
            {
               if(!flag)
               printf("%c",'a'+i);
               else
               printf(" %c",'a'+i);
               flag=1;
            }
         }
         if(!flag)
            printf("none");
         printf("\n");

     }return 0;


}

C - February 29 

描述

给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期)。

只有闰年有2月29日,满足以下一个条件的年份为闰年:

1. 年份能被4整除但不能被100整除

2. 年份能被400整除

输入

第一行为一个整数T,表示数据组数。

之后每组数据包含两行。每一行格式为"month day, year",表示一个日期。month为{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" , "December"}中的一个字符串。day与year为两个数字。

数据保证给定的日期合法且第一个日期早于或等于第二个日期。

输出

对于每组数据输出一行,形如"Case #X: Y"。X为数据组数,从1开始,Y为答案。

数据范围

1 ≤ T ≤ 550

小数据:

2000 ≤ year ≤ 3000

大数据:

2000 ≤ year ≤ 2×109

样例输入
4
January 12, 2012
March 19, 2012
August 12, 2899
August 12, 2901
August 12, 2000
August 12, 2005
February 29, 2004
February 29, 2012
样例输出
Case #1: 1
Case #2: 0
Case #3: 1
Case #4: 3


#include<stdio.h>
#include<string.h>
char str[13][10]= {"\0","January","February", "March", "April","May",
 "June", "July", "August","September", "October", "November", "December"};
int solve(int year)
{
     return year/400+year/4-year/100;
}
int main()
{
   int T,cas=1;
   scanf("%d",&T);
   while(T--)
   {
         int m1,m2,y1,y2,d1,d2,i;
         char mon1[10],mon2[10];
         scanf("%s %d,%d",mon1,&d1,&y1);
         scanf("%s %d,%d",mon2,&d2,&y2);
         for(i=0;i<=12;i++)
         {
             if(strcmp(mon1,str[i])==0)
             m1=i;
             if(strcmp(mon2,str[i])==0)
             m2=i;
         }
         if(m1>2)
            y1+=1;
         if((m2<2)||(m2==2&&d2<29))
            y2-=1;
        printf("Case #%d: %d\n",cas++,solve(y2)-solve(y1-1));
   }
   return 0;
}


D - 凯撒密码 

 Problem Description

在人类历史上,对信息保护的需求与对信息本身的需求一样久远。第一个用于加密和解密文本的编码方式是凯撒密码。凯撒密码约定的规则是,源文本中每个英文字母都被英文字母表中该字母后第三个位置的字母替换。例如,A->D, B->E, X->A, z->c。所有其他的符号都保持不变。现在请你写一个程序将加密后的文本解密。题目中大小写英文字母表分开,各自形成一个循环表。

 Input

本题有多组输入数据,每组数据只有一行,表示加密后的文字,由字母、空格、数字以及各种标点组成,文字长度不超过80个字符。

 Output

对于每组数据,输出一行,表示解密后的文字。

 Sample Input

Zhofrph wr icxsf2006!

 Sample Output

Welcome to fzupc2006!

#include <stdio.h>
#include <string.h>
int main()
{
    char a[100];
    int n,i,flag;
    while(gets(a))
    {
        int l=(int)strlen(a);
        n=-3;
        for(i=0; i<l; i++)
        {
            if( (a[i]>='a' && a[i]<='z') || (a[i]>='A' && a[i]<='Z') )
            {
                if(a[i]>=97)
                {
                    a[i]+=n;
                    if(a[i]<97)
                        a[i]+=26;
                }
                else
                {
                    a[i]+=n;
                    if(a[i]<65)
                       a[i]+=26;
                }
            }
        }
        printf("%s\n",a);
    }
    return 0;
}

E - 扫雷游戏 

http://acm.fzu.edu.cn/problem.php?pid=1056

Problem Description

扫雷是Windows自带的游戏。游戏的目标是尽快找到雷区中的所有地雷,而不许踩到地雷。如果方块上的是地雷,将输掉游戏。如果方块上出现数字,则表示在其周围的八个方块中共有多少颗地雷。

你的任务是在已知地雷出现位置的情况下,得到各个方块中的数据。

*....... “*”表示有地雷.*.. “.”表示无地雷....
经过处理应得到
*100
2210
1*10
1110

 Input

输入有多组数据,每组数据的第一行有两个数字,m,n(0<m,n<100)表示游戏中雷区的范围为m×n。接下来m行每行有n个字符。“*” 表示有地雷,“.”表示无地雷。最后一组数据m=0,n=0表示输入结束,不需要处理。

 Output

对于每组输入数据,输出结果,各方块数字间不留空格。每组结果之后有一个空行。

 Sample Input

2 3
***
...

4 4
*...
....
.*..
....

0 0

 Sample Output

***
232

*100
2210
1*10
1110

#include<stdio.h>
#include<string.h>
int main()
{
   int m,n,i,j,k;
   int x,y;
   char a[100][100];
   int b[100][100];
   while(scanf("%d%d",&n,&m)!=EOF&&(n||m))
   {
      memset(a,'0',sizeof(a));
      memset(b,0,sizeof(b));
      for(i=1;i<=n;i++)
      {
         getchar();
         for(j=1;j<=m;j++)
            scanf("%c",&a[i][j]);
      }
      for(i=1;i<=n;i++)
      {
            for(j=1;j<=m;j++)
            {
             
                   if(a[i][j]=='*')
                   {
                      b[i][j]=-1;
                   }
                   
                   
                   else if(a[i][j]=='.')
                     {
                          for(y=i-1;y<=i+1;y++)
                          {
                             for(x=j-1;x<=j+1;x++)
                              {
                                if(a[y][x]=='*')
                                  b[i][j]++;
                              }
                          }
                     }
            }
      }
      
        for(i=1;i<=n;i++)
        {
          for(j=1;j<=m;j++)
           {
           if(b[i][j]<0)
                printf("*");
           else 
                printf("%d",b[i][j]);
           }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



F - Trip For Meal 

http://codeforces.com/problemset/problem/876/A

Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is c meters.

For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).

Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.

Input

First line contains an integer n (1 ≤ n ≤ 100) — number of visits.

Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit's and Owl's houses.

Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit's and Eeyore's houses.

Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl's and Eeyore's houses.

Output

Output one number — minimum distance in meters Winnie must go through to have a meal n times.

Examples
input
3
2
3
1
output
3
input
1
2
3
5
output
0
Note

In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.

In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.


#include<stdio.h>
int min(int a,int b)
{
   return a<b?a:b;
}
int main()
{
    int n,a,b,c,i,k;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    if(n==1)
    {printf("0\n");}
    else if(n==2)
    {printf("%d\n",min(a,b));}
    else
    {printf("%d\n",min(a,b)+min(min(a,b),c)*(n-2));}
    
   return 0;
}


G - 今年暑假不AC 

https://vjudge.net/problem/17491/origin

Problem Description
“今年暑假不AC?”
“是的。”
“那你干什么呢?”
“看世界杯呀,笨蛋!”
“@#$%^&*%...”

确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。
作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)
 

Input
输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。
 

Output
对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。
 

Sample Input
 
 
121 33 40 73 815 1915 2010 158 186 125 104 142 90
 

Sample Output
 
 
5
 
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
     int r,l;
}a[105];
int cmp(node x,node y)
{
     return
         x.r<y.r;
}
int main()
{
     int n,i;
     while(~scanf("%d",&n),n)
     {
         for(i=0;i<n;i++)
         {
            scanf("%d%d",&a[i].l,&a[i].r);
         }
         sort(a,a+n,cmp);
         int sum=1;
         node p=a[0];
         for(i=1;i<n;i++)
         {
             if(p.r<=a[i].l)
             {
                sum++;
                p=a[i];
             }
         }
         printf("%d\n",sum);
     }
     return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值