A - Theatre Square
http://codeforces.com/problemset/problem/1/A
#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
Output
Sample Input
Sample Output
#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
Input
Output
Sample Input
Sample Output
#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
![](http://acm.fzu.edu.cn/image/Problem/1056.gif)
你的任务是在已知地雷出现位置的情况下,得到各个方块中的数据。
Input
Output
Sample Input
Sample Output
#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
#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
“是的。”
“那你干什么呢?”
“看世界杯呀,笨蛋!”
“@#$%^&*%...”
确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。
作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)
#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;
}