HDOJ2087:剪花布条——字符串处理、KMP

Problem Description
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?

 

Input
输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过1000个字符长。如果遇见#字符,则不再进行工作。

 

Output
输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。

 

Sample Input
abcde a3 aaaaaa aa #

 

Sample Output
0 3

代码:

#include
#include
int main(void)
{
	char str1[1010], str2[1010];
	while (~scanf("%s", str1))
	{
		if (str1[0] == '#')
			break;
		scanf("%s", str2);
		int i, j, l1, l2, temp = 0, k;
		l1 = strlen(str1);
		l2 = strlen(str2);
		for (i = 0; i
	

HDOJ2041

今天OJ 不能登录。可能是周末不上班吧。题目描述没复制下来。放上写的代码。

超级楼梯

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30969    Accepted Submission(s): 15992

Problem Description
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?

 

Input
输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。

 

Output
对于每个测试实例,请输出不同走法的数量

 

Sample Input
2 2 3

 

Sample Output
1 2

 

 

#include
int main()
{
	int n,m,i;
	int num[40]={1,2};
	scanf("%d",&n);
	for(i=2;i<40;i++)
		{
			num[i]=num[i-2]+num[i-1];
		}
	while(n--)
	{
		scanf("%d",&m);
		printf("%dn",num[m-2]);
	}
	return 0;
}

HDOJ2035:人见人爱A^B(快速幂取余)

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 23082 Accepted Submission(s): 16060
Problem Description
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”

Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。

Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。

Sample Input
2 3
12 6
6789 10000
0 0

Sample Output
8
984
1

//快速幂取余,简单版本
#include
int main()
{
	int a, b;
	while (scanf("%d %d", &a, &b) && (a + b))
	{
		int i, s = a;
		for (i = 0; i

 

HDOJ1108:最小公倍数

最小公倍数

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33998 Accepted Submission(s): 19029

Problem Description
给定两个正整数,计算这两个数的最小公倍数。

Input
输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.

Output
对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。

Sample Input
10 14

Sample Output
70


求最小公倍数的问题,辗转相除法解决。
代码:

#include 
int main()
{
	int a,b,ai,bi,temp;
	while (scanf ("%d %d",&a,&b) != EOF)
	{
		ai = a;
		bi = b;
		while (bi != 0)
		{
			temp = bi;
			bi = ai % bi;
			ai = temp;
		}
		printf ("%dn",a*b/ai);
	}
	return 0;
}

 

HDOJ1071:The area

The area

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7807 Accepted Submission(s): 5483

Problem Description
Ignatius bought a land last week, but he didn’t know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture, can you tell Ignatius the area of the land?

Note: The point P1 in the picture is the vertex of the parabola.

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0).

Output
For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.

Sample Input
2
5.000000 5.000000
0.000000 0.000000
10.000000 0.000000
10.000000 10.000000
1.000000 1.000000
14.000000 8.222222

Sample Output
33.33
40.69

Hint

For float may be not accurate enough, please use double instead of float.


数学问题,直接上代码:

#include
#include
int main()
{
    int n;
 	double x1,y1,x2,y2,x3,y3;
  	double a,b,c,k,t;
	double area1,area2;
    while(~scanf("%d",&n))
    while(n--)
    {
        scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
        a=(y2-y1)/pow((x2-x1),2);
        b=-2*a*x1;
        c=y1-a*x1*x1-b*x1;
        k=(y3-y2)/(x3-x2);
        t=y3-k*x3;
        area1=1.0/3*a*pow(x3,3)+1.0/2*(b-k)*pow(x3,2)+(c-t)*x3;
        area2=1.0/3*a*pow(x2,3)+1.0/2*(b-k)*pow(x2,2)+(c-t)*x2;
        printf("%.2lfn",area1-area2);
    }
    return 0;
}

HDOJ2053:Switch Game

Switch Game

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11000 Accepted Submission(s): 6702
Problem Description
There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).

Input
Each test case contains only a number n ( 0< n<= 10^5) in a line.

Output
Output the condition of the n-th lamp after infinity operations ( 0 – off, 1 – on ).

Sample Input
1
5

Sample Output
1
0

Hint
hint

Consider the second test case:

The initial condition : 0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …

The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.


#include
int main()
{
	int n, i, j;
	while (scanf("%d", &n) != EOF)
	{
		j = 0;
		for (i = 1; i 

放上AC代码:

 

题目的大意是有一排标号为1,2,3,4,5,……,n的台灯。初始状态都是灭灯的。在第一次操作的时候对序号为1的倍数的台灯改变状态(灭到亮或者是亮到灭),第二次操作时对序号为2的倍数的台灯改变状态,以此类推,如hint所示。问某只台灯的最后状态。

其实就是处理约数的问题。当操作次数大于序号后,那只台灯的状态就不会继续改变。问题就可以化简为得到某数的约数。如果约数为奇数,那么台灯为亮;否则台灯为灭。

HDOJ2037:今年暑假不AC

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 27554 Accepted Submission(s): 14558
Problem Description
“今年暑假不AC?”
“是的。”
“那你干什么呢?”
“看世界杯呀,笨蛋!”
“@#$%^&*%…”

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

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

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

Sample Input
12
1 3
3 4
0 7
3 8
15 19
15 20
10 15
8 18
6 12
5 10
4 14
2 9
0

Sample Output
5

动态规划+贪心,一开始想的太简单了。根本没有考虑到贪心。
放上一开始的Wa代码:

#include
int main()
{
	int t[100][2],num,n,ni,nii,time,s;
	scanf("%d",&n);
	for(ni=0;ni

放上一段比较简单的代码吧,根据节目时间长短来排序。然后依次观看时间最短的节目。(WA代码)

#include
int main()
{
	int st[100], end[100];
	int n, a, b;
	while (scanf("%d", &n) && n != 0)
	{
		for (int i = 0; iend[j])按后面排好  交换
			if (end[i]>end[j])
			{
				a = end[i];
				end[i] = end[j];
				end[j] = a;
				b = st[i];
				st[i] = st[j];
				st[j] = b;
				// 再接着开始排列
			}
		}
		int sum = 0, max = 0;
		for (int i = 0; i= max)
		{
			sum++;
			max = end[i];
		}
		printf("%dn", sum);
	}
	return 0;
}

放上已经AC的C++代码。不是我写的。

#include
#include
#include
#define MAX 1000
using namespace std;
pair p[MAX];
int main()
{
	int n;
	int s, e;
	while (scanf("%d", &n)>0 && n)
	{
		for (int i = 0; i
	

HDOJ2043:密码

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29908 Accepted Submission(s): 12022
Problem Description

网上流传一句话:”常在网上飘啊,哪能不挨刀啊~”。其实要想能安安心心地上网其实也不难,学点安全知识就可以。

首先,我们就要设置一个安全的密码。那什么样的密码才叫安全的呢?一般来说一个比较安全的密码至少应该满足下面两个条件:

(1).密码长度大于等于8,且不要超过16。
(2).密码中的字符应该来自下面“字符类别”中四组中的至少三组。

这四个字符类别分别为:
1.大写字母:A,B,C…Z;
2.小写字母:a,b,c…z;
3.数字:0,1,2…9;
4.特殊符号:~,!,@,#,$,%,^;

给你一个密码,你的任务就是判断它是不是一个安全的密码。

Input
输入数据第一行包含一个数M,接下有M行,每行一个密码(长度最大可能为50),密码仅包括上面的四类字符。

Output
对于每个测试实例,判断这个密码是不是一个安全的密码,是的话输出YES,否则输出NO。

Sample Input
3
a1b2c3d4
Linle@ACM
^~^@^@!%

Sample Output
NO
YES
NO

先发一下代码:

#include
#include
int main()
{
	int n, ni, l;
	int q, w, e, r;
	char a[50];
	scanf("%d", &n);
	getchar();
	while (n--)
	{
		memset(a, 0, sizeof(a));
		q = w = e = r = 0;
		gets(a);
		ni = l= strlen(a);
		ni--;
		while (a[ni]!=' ')
		{
			if (a[ni] >= 65 && a[ni] = 97 && a[ni] = 48 && a[ni] = 3&&l>=8&&l

WA的原因是没有判断/0结束标志,数组搜索出了问题。是一道水题。WA了4次……

HDOJ1002:A + B Problem II

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 210904 Accepted Submission(s): 40642
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.

Output
For each test case, you should output two lines. The first line is “Case #:”, # means the number of the test case. The second line is the an equation “A + B = Sum”, Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

Sample Input
2
1 2
112233445566778899 998877665544332211

Sample Output
Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

记得刚注册ACM账号的时候,在连续解决掉1000和1001这两道问题后。就毫不犹豫的点开了1002。

快一年了……终于把这个坑补完了。

先放上来,等我仔细研究之后再放代码吧。

HDOJ2071:Max Num

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13674 Accepted Submission(s): 8661
Problem Description
There are some students in a class, Can you help teacher find the highest student .

Input
There are some cases. The first line contains an integer t, indicate the cases; Each case have an integer n ( 1 ≤ n ≤ 100 ) , followed n students’ height.

Output
For each case output the highest height, the height to two decimal plases;

Sample Input
2
3 170.00 165.00 180.00
4 165.00 182.00 172.00 160.00

Sample Output
180.00
182.00
 

水题,放上代码:

#include
int main()
{
	int n,ni,j,ji;
	double num[100],ans;
	scanf("%d",&n);
	for(ni=0;nians)
			{
				ans=num[ji];
			}
		}
		printf("%.2lfn",ans);
	}
	return 0;
}

其实还是有运气的成分在里面,因为样例中的数据可能都是精确到小数点后两位,所以可以通过.2lf直接输出.还没有想到可以直接根据输入数据给出输出精度的方法.