统计数字问题
Time Limit: 1000 ms Memory Limit: 32768 KiB
Submit Statistic
Problem Description

一本书的页码从自然数1 开始顺序编码直到自然数n。书的页码按照通常的习惯编排,每个页码都不含多余的前导数字0。例如,第6 页用数字6 表示,而不是06 或006 等。数字计数问题要求对给定书的总页码n,计算出书的全部页码中分别用到多少次数字0,1, 2,…,9。给定表示书的总页码的10 进制整数n (1≤n≤109) 。计算书的全部页码中分别用到多少次数字0,1,2,…,9。
Input

输入数据只有1 行,给出表示书的总页码的整数n。
Output

输出数据共有10行,在第k行输出页码中用到数字k-1 的次数,k=1,2,…,10。
Sample Input

11
Sample Output

1
4
1
1
1
1
1
1
1
1

import java.util.Scanner;
public class Main {
	static int[] results = new int[10];
	static int pages = 1;
	static int i;
	static void count(int n) {
		while (n > 0)
		{
			results[n % 10] += 1;
			 n = n / 10;
		}
	}
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		for (i = 0; i < 10; i++)
			results[i] = 0;
		pages = input.nextInt();
		for (i = 1; i <= pages; i++)
			count(i);
		for (i = 0; i < 10; i++)
			 System.out.println(results[i]);
	}

}

LCM的个数
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

对于我们来说求两个数的LCM(最小公倍数)是很容易的事,现在我遇到了一个问题需要大家帮助我来解决这问题,问题是:给你一个数n,然后统计有多少对(a<=b) LCM(a,b)=n;例如LCM(a,b)=12; 即(1,12),(2,12),(3,12),(4,12),(6,12),(12,12),(3,4),(4,6);
Input

输入数组有多组,每组数据包含一个整数n(n<=10^9);
Output

输出每组数据的对数。
Sample Input

2
3
4
6
Sample Output

2
2
3
5

import java.util.Scanner;
public class Main {
	public static int f(int a, int b) {
		if (b == 0)
			return a;
		return f(b, a % b);
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while (cin.hasNext())
		{
			int n = cin.nextInt();
			int num = 0, sum = 0;
			int a[] = new int[108611];
			for (int i = 1; i * i <= n; i++)
			{
				if (n % i == 0)
				{
					a[num++] = i;
					if (i * i != n)
						a[num++] = n / i;
				}
			}
			for (int i = 0; i < num; i++)
			{
				for (int j = i; j < num; j++)
				{
					if (a[i] / f(a[i], a[j]) * a[j] == n)
						sum++;
				}
			}
			System.out.println(sum);
		}
		cin.close();
	}

}

多项式求和
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

多项式描述如下:
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 ……
先请你求出多项式前n项的和。
Input

第一行输入一个数T代表测试数据个数(T<=1000)。接下来T行每行1个数代表n(0<=n< 2^31)。

Output

对于每个输入样例,输出多项式和的结果(结果精确到小数点后两位)。每行输出一个结果。
Sample Input

2
1
2
Sample Output

1.00
0.50

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
			int n=in.nextInt();
			for(int i=0;i<n;i++)
			{
				int a=in.nextInt();
				double sum;
				if(a>100) a=100;
				int m=1;
				sum=0;
				for(int t=1;t<=a;t++)
				{
					 if(t%2==0)
					 {
						 sum-=1.0/t;
					 }
					 else
					 {
						 sum+=1.0/t;
					 }
				}
				System.out.printf("%.2f\n",sum);
			}
		in.close();
	}

}

This is an YY Problem
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

YY 小时候性格孤僻,小朋友们都不喜欢跟他一起玩,于是他养成了一个奇怪的习惯:每天都在屋子里走来走去。有一天,他突然想到了一个问题,假设屋子是一个N x M 的矩形,里面铺着 1 x 1 的地板砖(即共有 N 行,每行 M 块地板砖),他想知道沿着对角线从左上角走到右下角会走过多少块地板砖( YY 可以看做一个质点)。样例中四组数据的对应图片如下图所示:

Input

输入数据的第一行为一个正整数 T(T ≤ 100),代表共有 T 组测试数据。
对于每组测试数据:
输入两个正整数 N 和 M (1 ≤ N, M ≤ 104)。
Output

对于每组测试数据,输出一个正整数 R,表示走过的地板砖数。
Sample Input

4
4 1
3 2
4 2
4 4
Sample Output

4
4
4
4

import java.util.Scanner;
public class Main {
	public static int f(int n, int m, int x)
	{
		return n * x / m;
	}
	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t, i, j, n, m, s;
        t = in.nextInt();
        for(i = 1; i <= t; i++)
        {
        	n = in.nextInt();
        	m = in.nextInt();
        	s = 0;
        	for(j = 1; j <= m - 1; j++)
        	{
        		s += (int)f(n, m, j);
        	}
        	s = m * n - 2 * s;
        	System.out.println(s);
        }
        in.close();
    }
}

机器人II
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

自从xiao_wu发明了只能向左转与向右转的机器人以后,热血沸腾的他又给机器人加了一个操作。假设机器人在二维坐标系的原点,一开始面向Y轴正方向(北N),现在给你一个仅由’L’,’R’,’M’的串,其中L表示向左转,R表示向右转,M表示向所面对的方向走一个单位的距离,试问经过操作过后,机器人的坐标和所面对的方向。
北(N),西(W),东(E),南(S)。
Input

第一行输入一个T(T<150),表示任务的个数
对于每个任务,输入一个串。(每个任务开始前机器人在原点,面向北(N),既Y轴正方向)
串长度不大于100
Output

对于每个任务,输出两个数表示机器人的坐标,一个字符表示机器人的面朝的方向。
Sample Input

2
LRMLL
LMRMMLLL
Sample Output

0 1 S
-1 2 E

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int i,j,t,l,x,y,d;
char c='0';
t=reader.nextInt();
reader.nextLine();
for(j=1;j<=t;j++)
{
x=0;
y=0;
d=1;
String s;
s=reader.nextLine();
l=s.length();
char[] a=s.toCharArray();
for(i=0;i<l;i++)
{
if(a[i]=='L')
{
if(d<=1)
{
d=4;
}
else
{
d--;
}
}
if(a[i]=='R')
{
if(d>=4)
{
d=1;
}
else
{
d++;
}
}
if(a[i]=='M')
{
if(d==1)
{
y++;
}
else if(d==2)
{
x++;
}
else if(d==3)
{
y--;
}
else
{
x--;
}
}
}
if(d==1) c='N';
if(d==2) c='E';
if(d==3) c='S';
if(d==4) c='W';
System.out.printf("%d %d %c\n",x,y,c);
}
reader.close();
}

}

Time
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

Digital clock use 4 digits to express time, each digit is described by 3*3 characters (including”|”,”_”and” “).now given the current time, please tell us how can it be expressed by the digital clock.
Input

There are several test cases.
Each case contains 4 integers in a line, separated by space.
Proceed to the end of file.
Output

For each test case, output the time expressed by the digital clock such as Sample Output.
Sample Input

1 2 5 6
2 3 4 2
Sample Output

_  _  _

| || |_
||_ |||


_| ||| |
|
| ||

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1[]={" _ ","   "," _ "," _ ","   "," _ "," _ "," _ "," _ "," _ "};
        String s2[]={"| |","  |"," _|"," _|","|_|","|_ ","|_ ","  |","|_|","|_|"};
        String s3[]={"|_|","  |","|_ "," _|","  |"," _|","|_|","  |","|_|"," _|"};
        int a, b, c, d;
        while(in.hasNextLine())
        {
        	a = in.nextInt();
        	b = in.nextInt();
        	c = in.nextInt();
        	d = in.nextInt();
        	System.out.printf("%s%s%s%s\n", s1[a], s1[b], s1[c], s1[d]);
        	System.out.printf("%s%s%s%s\n", s2[a], s2[b], s2[c], s2[d]);
        	System.out.printf("%s%s%s%s\n", s3[a], s3[b], s3[c], s3[d]);
        }
        in.close();
    }
}

画笑脸
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

毛线们表示那些算法题实在太难了,做不出来,就干脆用 C 语言画些笑脸来娱乐大家~
毛线们只会画一种笑脸,但是他们可以画出任意大小出来,画法见 Sample

Input

多组数据,每组数据只有一个数 N(1<=N<=20),表示笑脸的大小

Output

把笑脸画出来吧~
注意:不要任何多余的空格和空行,每组数据间空一行

示例输出

Sample Input

1
2
3

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n, i, j;
        while(in.hasNextLine())
        {
        	n = in.nextInt();
        	for(i = 1; i <= n; i++)
        	{
        	for(j = 1; j <= n - i; j++)
        	{
        	System.out.printf(" ");
        	}
        	System.out.printf("/");
        	for(j = 1; j <= 2 * (i - 1); j++)
        	{
        	System.out.printf(" ");
        	}
        	System.out.printf("\\");
        	for(j = 2 * (n - i) + n; j >= 1; j--)
        	{
        	System.out.printf(" ");
        	}
        	System.out.printf("/");
        	for(j = 1; j <= 2 * (i - 1); j++)
        	{
        	System.out.printf(" ");
        	}
        	System.out.printf("\\");
        	System.out.println();
        	}
        	for(i = 1; i <= n - 1; i++)
        	{
                System.out.println();
        	}
            for(i = 1; i <= 2 * n; i++)
            {
                System.out.print(" ");
            }
            for(i = 1; i <= n; i++)
            {
                System.out.print("_");
            }
            System.out.println();
        	System.out.println();
        }
        in.close();
    }
}
10-06 14:26