cf 215 C. Crosses yy题

链接:http://codeforces.com/problemset/problem/215/C

C. Crosses

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a board with a grid consisting of n rows and m columns,
the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from
left to right. In this grid we will denote the cell that lies on row number i and column number j as (i,?j).

A group of six numbers (a,?b,?c,?d,?x0,?y0),
where 0?≤?a,?b,?c,?d, is a cross, and there
is a set of cells that are assigned to it. Cell (x,?y)belongs to this set if at
least one of two conditions are fulfilled:

  • |x0?-?x|?≤?a and |y0?-?y|?≤?b
  • |x0?-?x|?≤?c and |y0?-?y|?≤?d

The picture shows the
cross (0,?1,?1,?0,?2,?3) on the grid 3?×?4.

Your task is to find the number of different groups of six numbers, (a,?b,?c,?d,?x0,?y0) that
determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any
of its cells is in the range of the grid (that is for each cell (x,?y) of the cross 1?≤?x?≤?n; 1?≤?y?≤?m holds).
The area of the cross is the number of cells it has.

Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.

Input

The input consists of a single line containing three integers nm and s (1?≤?n,?m?≤?500, 1?≤?s?≤?n·m).
The integers are separated by a space.

Output

Print a single integer — the number of distinct groups of six integers that denote crosses with area s and that are fully placed on then?×?m grid.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.

Sample test(s)

input

2 2 1

output

4

input

3 4 5

output

4

Note

In the first sample the sought groups of six numbers are: (0,?0,?0,?0,?1,?1), (0,?0,?0,?0,?1,?2), (0,?0,?0,?0,?2,?1), (0,?0,?0,?0,?2,?2).

In the second sample the sought groups of six numbers are: (0,?1,?1,?0,?2,?2), (0,?1,?1,?0,?2,?3), (1,?0,?0,?1,?2,?2), (1,?0,?0,?1,?2,?3).

题意:

给你n*m矩阵,问有多少个不同的    (a,?b,?c,?d,?x0,?y0) 
  面积等于s。

  • |x0?-?x|?≤?a and |y0?-?y|?≤?b
  • |x0?-?x|?≤?c and |y0?-?y|?≤?d

满足这个条件 相当于两个一x0 ,y0 为中心的,边长全为奇数的矩形并。

一个矩形长为2a+1,宽为2b+1   另一个是(2*c+1) * (2*d+1)

做法:

枚举其中一个矩形的长和宽。

如果面积超过s显然不行。

如果等于s,那么另一个肯定比它小或者相等。

ans+=(n-i/2*2)*(m-j/2*2)*   (((i/2+1)*(j/2+1)-1)*2+1);

(n-i/2*2)*(m-j/2*2) 这个算有多少位子 可以做为矩形 中心

(((i/2+1)*(j/2+1)-1)*2+1)  枚举那个小的边长

如果小于s的话,枚举另一个矩阵的长度,长度小于i

然后计算宽度。

宽度如果小于m并且也是奇数

ans+=(n-i/2*2)*(m-wid/2*2)*2;    枚举中心点可以在的位置,因为两个矩形不同所以abcd可以对换 所以*2

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <malloc.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <set>
#include <map>

int main()
{

	int n,m,s;

	scanf("%d%d%d",&n,&m,&s);
	__int64 ans=0;
	for(int i=1;i<=n;i+=2)//枚举比较长的长方形 长度
	{
		for(int j=1;j<=m;j+=2)
		{
				if(i*j>s)
					continue;
				else if(i*j==s)//一个包含另一个
				{
					ans+=(n-i/2*2)*(m-j/2*2)*   (((i/2+1)*(j/2+1)-1)*2+1);
					// 位子*枚举边长
				}
				else
				{
					for(int len=1;len<i;len+=2)//长小的
					{
						if((s-i*j)%len==0)
						{
							int wid=(s-i*j)/(len)+j;
							//长的 j
							//宽的 wid
							if(wid<=m&&(wid&1))
							ans+=(n-i/2*2)*(m-wid/2*2)*2;
							//确定位置 因为不同 所以abcd可以换 *2
						}
					}
				}
		}
	}
	printf("%I64d\n",ans);

	 scanf("%d%d%d",&n,&m,&s);
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-27 17:19:48

cf 215 C. Crosses yy题的相关文章

CF 628A --- Tennis Tournament --- 水题

CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m <=n)个人进行比赛,剩余的n-m个人直接晋级, 直至只剩一人为止,问总共需要的水的数量和毛巾的数量 解题思路:毛巾数很简单: n*p即可 水的数量:1,2,4,8,16,32,64,128,256,512,提前打成一个表, 根据当前剩余的人数n在表中二分查找最大的小于等于n的数,结果即为本次进行比赛

CF 628B New Skateboard --- 水题

CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整除: 利用这个性质,先特判第一位数字是否能被4整除,可以则++cnt, 之后从第二位数字开始,设当前位为i,先判断a[i]能否被4整除,可以则++cnt, 再判断a[i-1]*10+a[i]能否被4整除,可以则cnt = cnt + (i) 相关证明: 设一整数各个位置为a1,a2,a3,...,an,b

CF#215 DIV2: B. Sereja and Suffixes

Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1,?l2,?...,?lm (1?≤?li?≤?n). For each number li he wants to know

CF 714D Searching Rectangles 交互题 二分

题意:交互题,已知一个n*n的地图,电脑藏了两个不相交的矩形(矩形的边和坐标轴平行).每次向电脑询问左下[x1,y1]右上[x2,y2]的矩形内完全包含多少个藏着的矩形.n<=2^16.请在200次内猜出两个矩形左下,右上坐标. 先二分出两个不相交矩形的分界线,要么横着要么竖着.接在在每一快中二分出矩形的四条边即可(最左,右,上,下边界) #include <bits/stdc++.h> using namespace std; int n,ans[20],cnt=0; inline i

!HDU 4145--思维(yy题)--(细节)

题意:有两个中心点A,B,有其他n个点,每个点到中心点都有以它们的距离为半径的圆的辐射范围,求最小的辐射范围半径能覆盖所有的点. 分析:这题纯靠想解题方法.一开始方向走错了一直WA.开始的想法:每输入一个点就计算它到A,B的距离,只取较小值,不断更新结果.WA的过程中才慢慢发现这样做会有很多特殊情况,但当时都没想过要换思路,只是不断地增加代码讨论情况,下次一定记得发现方法有很多不足就转换思路.正确做法:每输入一个点只计算它到A点的距离,从大到小排序,遍历依次判断加入把这一点归到B的覆盖范围是否结

cf 55D 数位dp 好题

/* 刚开始我考虑0的情况,想将他剔除就将lcmn设为-1,这样还要判断0和lcmn是-1的情况很麻烦而且但是一直出错 后来觉得不用管0的情况就行了,可以认为符合. 解:将lcmn离散化,因为1-9的公倍数必是2520的因子并且只有48个 所以用一个数组离散化,记忆的时候直接调用离散数组即可 因为一个数的所有数字的最小公倍数必定是2520的因子,所以将这个数对2520取余缩小范围并记忆 三维,第一个长度,第二个对2520取余,第三个是lcm值 */ #include<stdio.h> #inc

noj 2069 赵信的往事 [yy题 无限gcd]

njczy2010 2069 Accepted 31MS   224K 1351Byte G++ 2014-11-13 13:32:56.0 坑爹的无限gcd,,,尼玛想好久,原来要x对y算一次,y再对x算一次,,, 赵信的往事 时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte总提交 : 20            测试通过 : 2 描述 赵信——德玛西亚的总管,可谓一人之下,万人之上.但谁能想到,他以前在诺克萨斯的角斗

CF 1097D - Hello 2019 D题: Makoto and a Blackboard

目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门 ?Portal ?原题目描述在最下面. ?给一个数n,由k次操作.每次操作等概率的把n变成他的一个因数(\(1\leq x\leq n\)),问k次操作后得到的数的期望是多少. Solution: \(n = p1^{a1}*...*pm^{am}\) 积性函数: \(fk(n) = fk(p1^{a1})*...*fk(pm^{am})\) \(dp[j]\

一道cf水题再加两道紫薯题的感悟

1. 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. 2. 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整除.或者把分子上的每个数进行素数因子分解,分母上的数也进行素数因子分解,若分子上的与分母上相同素数因子进行比较,分子上的素数因子指数大于分母位置上的,则证明可整除. 3. 遇到乘法的时候注意越界问题. 4. 遇到求某一个区间内,满足某一特征的数的个数,而这个特征与因子,约数有关,尝试用埃筛的方法