lightoj1008

maksyuki 发表于 oj 分类,标签:
0

1008 - Fibsieve`s Fantabulous Birthday

Among these gifts there was an N x N glass chessboard that had a light in each of its cells. When the board was turned on a distinct cell would light up every second, and then go dark.Fibsieve had a fantabulous (yes, it's an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year.

The cells would light up in the sequence shown in the diagram. Each cell is marked with the second in which it would light up.

In the first second the light at cell (1, 1) would be on. And in the 5th second the cell (3, 1) would be on. Now, Fibsieve is trying to predict which cell will light up at a certain time (given in seconds). Assume that N is large enough.

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case will contain an integer S (1 ≤ S ≤ 1015) which stands for the time.

Output

For each case you have to print the case number and two numbers (x, y), the column and the row number.

Sample Input

Output for Sample Input

382025 Case 1: 2 3Case 2: 5 4Case 3: 1 5

 

 

题目类型:简单递推

算法分析:首先得到对角线上数的递推公式,然后求得最接近输入数S的对角线上的数ans,然后判断S是否在[ans – (temp - 1), ans + (temp + 1)]中,其中temp表示对角线元素的坐标(temp,temp),然后再分类讨论即可

 

lightoj1007

maksyuki 发表于 oj 分类,标签:
0

1007 - Mathematically Hard

In this problem, you will be given two integers a and b. You have to find the summation of the scores of the numbers from a to b (inclusive). The score of a number is defined as the following function.Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable.

score (x) = n2, where n is the number of relatively prime numbers with x, which are smaller than x

For example,

For 6, the relatively prime numbers with 6 are 1 and 5. So, score (6) = 22 = 4.

For 8, the relatively prime numbers with 8 are 1, 3, 5 and 7. So, score (8) = 42 = 16.

Now you have to solve this task.

Input

Input starts with an integer T (≤ 105), denoting the number of test cases.

Each case will contain two integers a and b (2 ≤ a ≤ b ≤ 5 * 106).

Output

For each case, print the case number and the summation of all the scores from a to b.

Sample Input

Output for Sample Input

36 68 82 20 Case 1: 4Case 2: 16Case 3: 1237

 

 

题目类型:欧拉函数

算法分析:使用递推的方法将5e6以内的欧拉函数值算出来,进而求前缀和,最后直接查询即可,注意本题数据比较大,只能使用unsigned long long定义euler数组

 

lightoj1002

maksyuki 发表于 oj 分类,标签:
0

1002 - Country Roads

For example, in the above picture, if we want to go from 0 to 4, then we can chooseI am going to my home. There are many cities and many bi-directional roads between them. The cities are numbered from 0 to n-1 and each road has a cost. There are m roads. You are given the number of my city t where I belong. Now from each city you have to find the minimum cost to go to my city. The cost is defined by the cost of the maximum road you have used to go to my city.

1)      0 - 1 - 4 which costs 8, as 8 (1 - 4) is the maximum road we used

2)      0 - 2 - 4 which costs 9, as 9 (0 - 2) is the maximum road we used

3)      0 - 3 - 4 which costs 7, as 7 (3 - 4) is the maximum road we used

So, our result is 7, as we can use 0 - 3 - 4.

Input

Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with a blank line and two integers n (1 ≤ n ≤ 500) and m (0 ≤ m ≤ 16000). The next m lines, each will contain three integers u, v, w (0 ≤ u, v < n, u ≠ v, 1 ≤ w ≤ 20000)indicating that there is a road between u and v with cost w. Then there will be a single integer t (0 ≤ t < n). There can be multiple roads between two cities.

Output

For each case, print the case number first. Then for all the cities (from 0 to n-1) you have to print the cost. If there is no such path, print 'Impossible'.

Sample Input

Output for Sample Input

25 60 1 5

0 1 4

2 1 3

3 0 7

3 4 6

3 1 8

1

 

5 4

0 1 5

0 1 4

2 1 3

3 4 7

1

Case 1:403

7

7

Case 2:

4

0

3

Impossible

Impossible

Note

Dataset is huge, user faster I/O methods.

 

题目类型:最大容量路(bellman-ford)

算法分析:使用边表存储边的信息,然后使用bellman-ford迭代n – 1次计算dis数组的值,dis[i]表示节点i到目标节点的最大容量值,递推公式为

dis[edge[j].u] = min (dis[edge[j].u], max (edge[j].w, dis[edge[j].v]));注意使用Floyd会TLE

 

bzoj3229

maksyuki 发表于 oj 分类,标签:
0

3229: [Sdoi2008]石子合并

Description

在一个操场上摆放着一排N堆石子。现要将石子有次序地合并成一堆。规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的得分。

试设计一个算法,计算出将N堆石子合并成一堆的最小得分。

阅读全文 »

bzoj2818

maksyuki 发表于 oj 分类,标签:
0

2818: Gcd

Description

给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对.

Input

一个整数N

阅读全文 »

bzoj2705

maksyuki 发表于 oj 分类,标签:
0

2705: [SDOI2012]Longge的问题

Description

Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题。现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N)。

Input

一个整数,为N。

阅读全文 »

bzoj2190

maksyuki 发表于 oj 分类,标签:
0

2190: [SDOI2008]仪仗队

Description

作为体育委员,C君负责这次运动会仪仗队的训练。仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图)。 现在,C君希望你告诉他队伍整齐时能看到的学生人数。

阅读全文 »

sgu112

maksyuki 发表于 oj 分类,标签:
0
  1. ab-ba

You are given natural numbers a and b. Find ab-ba.

Input

Input contains numbers a and b (1≤a,b≤100).

阅读全文 »

sgu105

maksyuki 发表于 oj 分类,标签:
0
  1. Div 3

There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determine amount of numbers in it that are divisible by 3.

Input

Input contains N (1<=N<=231 - 1).

Output

Write answer to the output.

Sample Input

4

Sample Output

2

 

题目类型:简单数学

算法分析:打表发现各位和能整除3的数是有规律的,直接按照规律求解即可(任意数模3的取值只有0、1和2)

 

sgu104

maksyuki 发表于 oj 分类,标签:
0
  1. Little shop of flowers

PROBLEM

You want to arrange the window of your flower shop in a most pleasant way. You have bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through V, where V is the number of vases, from left to right so that the vase 1 is the leftmost, and the vase V is the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 and F. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunch i must be in a vase to the left of the vase containing bunch j whenever i < j. Suppose, for example, you have bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers.

Each vase has a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values are presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0.

V A S E S
1 2 3 4 5
Bunches 1 (azaleas) 7 23 -5 -24 16
2 (begonias) 5 21 -4 10 23
3 (carnations) -21 5 -4 -20 20

 

According to the table, azaleas, for example, would look great in vase 2, but they would look awful in vase 4.

To achieve the most pleasant effect you have to maximize the sum of aesthetic values for the arrangement while keeping the required ordering of the flowers. If more than one arrangement has the maximal sum value, any one of them will be acceptable. You have to produce exactly one arrangement.

ASSUMPTIONS

  • 1 ≤ F ≤ 100 where F is the number of the bunches of flowers. The bunches are numbered 1 through F.
  • F ≤ V ≤ 100 where V is the number of vases.
  • -50 £ Aij £ 50 where Aij is the aesthetic value obtained by putting the flower bunch i into the vase j.

Input

  • The first line contains two numbers: FV.
  • The following F lines: Each of these lines contains V integers, so that Aij is given as the j’th number on the (i+1)’st line of the input file.

Output

  • The first line will contain the sum of aesthetic values for your arrangement.
  • The second line must present the arrangement as a list of F numbers, so that the k’th number on this line identifies the vase in which the bunch k is put.

Sample Input

3 5

7 23 -5 -24 16

5 21 -4 10 23

-21 5 -4 -20 20

Sample Output

53

2 4 5

 

题目类型:线性DP+记录路径

算法分析:dp[i][j]表示前i种花在第j个花瓶中所取得的最大特征值。par[i][j]表示前i种花在第j个花瓶取得最大值时从前i-1种花转移来的花瓶序号。状态转移方程为:dp[i][j] += max{dp[i-1][k]} i - 1 <= k < j,最后输出最大值并回溯求解列号

 

sgu102

maksyuki 发表于 oj 分类,标签:
0
  1. Coprimes

For given integer N (1<=N<=104) find amount of positive numbers not greater than N that coprime with N. Let us call two positive integers (say, A and B, for example) coprime if (and only if) their greatest common divisor is 1. (i.e. A and B are coprime iff gcd(A,B) = 1).

Input

Input file contains integer N.

Output

Write answer in output file.

Sample Input

9

Sample Output

6

题目类型:Euler函数计算

算法分析:直接使用试除法求解即可