gcj 2017 A

来源:互联网 发布:sql server 创建表语句 编辑:程序博客网 时间:2024/06/08 09:08

在这里记录下吧,反正这里已经成为我碎碎念的地方了。

昨天gcj2017A轮开始。晚了点才进,三个题目都看了下,第一个我只能给出正常数数的方案,分类讨论,加起来这样= = 第二个模板匹配,一开始自己想了下逻辑,但是发现有不对的地方,觉得要用回溯吧;第三个Cube的我不知道用什么去比较他们的大小和给出策略,总不能真的建个坐标系求解吧(真的建的话,怎么求解来着?)

关于语言…感觉好久没用C++了,笔记本上也没装Java,于是用了Python3。写好后因为2和3的区别改了点语法错,接着因为一个括号匹配问题没发现一直没法编译,后来测试用例发现算法有错,直到round A结束了。

今天怎么也想不出逻辑里错误的地方,于是去下别人的solution,下了几个都是C++实现的,关键是程序里每一个是像我这样慢慢数的,于是乎没看懂= =后来发现我测试出错是因为没有取模,于是small input 过了。
接着跑large input,但是因为我用了两层循环,于是跪了。

可是看不懂+ +,贴一下题目好了
——————————————
Problem A. Square Counting
Problem

Mr. Panda has recently fallen in love with a new game called Square Off, in which players compete to find as many different squares as possible on an evenly spaced rectangular grid of dots. To find a square, a player must identify four dots that form the vertices of a square. Each side of the square must have the same length, of course, but it does not matter what that length is, and the square does not necessarily need to be aligned with the axes of the grid. The player earns one point for every different square found in this way. Two squares are different if and only if their sets of four dots are different.

Mr. Panda has just been given a grid with R rows and C columns of dots. How many different squares can he find in this grid? Since the number might be very large, please output the answer modulo 109 + 7 (1000000007).

Input

The first line of the input gives the number of test cases, T. T lines follow. Each line has two integers R and C: the number of dots in each row and column of the grid, respectively.
Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the number of different squares can be found in the grid.
Limits

1 ≤ T ≤ 100.
Small dataset

2 ≤ R ≤ 1000.
2 ≤ C ≤ 1000.
Large dataset

2 ≤ R ≤ 109.
2 ≤ C ≤ 109.
Sample

Input

Output

4
2 4
3 4
4 4
1000 500

Case #1: 3
Case #2: 10
Case #3: 20
Case #4: 624937395
——————————

以下是名为tulsyan的用户的solution

MOD = 10**9+7t=int(raw_input())for qq in xrange(t):    r, c = map(int, raw_input().split())    k = min(r, c)    tmp = k*(k + 1) * (c * (-4*k + 6*r - 2) + 3*k*k + k * (3 - 4*r) - 2*r)    tmp /= 12    # print tmp    ans = tmp    # ans = 0    # for i in xrange(1, k + 1):    #     tmp = ((r - i) * (c - i) * i)    #     # print tmp    #     if (r - i) < 0 or (c - i) < 0:    #         break    #     ans += tmp    print "Case #{0}: {1}".format(qq + 1, ans % MOD)
0 0
原创粉丝点击