cf 215 C. Crosses yy题
链接:http://codeforces.com/problemset/problem/215/C
2 seconds
256 megabytes
standard input
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.
The input consists of a single line containing three integers n, m and s (1 ≤ n, m ≤ 500, 1 ≤ s ≤ n·m).
The integers are separated by a space.
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.
2 2 1
4
3 4 5
4
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;
}
cf 215 C. Crosses yy题的更多相关文章
- CF 628B New Skateboard --- 水题
CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...
- CF 628A --- Tennis Tournament --- 水题
CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...
- CF #636 (Div. 3) 对应题号CF1343
unrated 选手悠闲做题,然后只做出四个滚蛋了 符合 div3 一贯风格,没啥难算法 E最后就要调出来了,但还是赛后才A的 CF1343A Candies 传送门 找到一个 \(x\),使得存在一 ...
- [YY题]HDOJ5288 OO’s Sequence
题意:求这个式子 $\sum \limits_{i=1}^{n} \sum \limits_{j=1}^{m} f(i, j) mod (10^9 + 7)$ 的值 就是对每个区间[i, j]枚举区间 ...
- CF 420B Online Meeting 模拟题
只是贴代码,这种模拟题一定要好好纪念下 TAT #include <cstdio> #include <cstring> #include <algorithm> ...
- CF 214B Hometask(想法题)
题目链接: 传送门 Hometask Time Limit: 2 seconds Memory Limit: 256 megabytes Description Furik loves mat ...
- Codeforces Round #215 (Div. 2) D题(离散化+hash)
D. Sereja ans Anagrams time limit per test 1 second memory limit per test 256 megabytes input standa ...
- HDU-4414 Finding crosses 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4414 直接暴力判断即可. //STATUS:C++_AC_15MS_232KB #include &l ...
- noj 2069 赵信的往事 [yy题 无限gcd]
njczy2010 2069 Accepted 31MS 224K 1351Byte G++ 2014-11-13 13:32:56.0 坑爹的无限gcd,,,尼玛想好久,原来要x对y算一次,y再 ...
随机推荐
- 使用Phaser开发你的第一个H5游戏(一)
本文来自网易云社区 作者:王鸽 不知你是否还记得当年风靡一时的2048这个游戏,一个简单而又不简单的游戏,总会让你在空闲时间玩上一会儿. 在这篇文章里,我们将使用开源的H5框架--Phaser来重现这 ...
- 大数据学习——Storm学习单词计数案例
需求:计算单词在文档中出现的次数,每出现一次就累加一次 遇到的问题 这个问题是<scope>provided</scope>作用域问题 https://www.cnblogs. ...
- Java程序员---技能树
计算机基础: 比如网络相关的知识. 其中就包含了 TCP 协议,它和 UDP 的差异.需要理解 TCP 三次握手的含义,拆.粘包等问题. 当然上层最常见的 HTTP 也需要了解,甚至是熟悉. 这块推荐 ...
- HDU-5536 Chip Factory,又见字典树,好题+1!
Chip Factory 题意:一个n个数的数列,求三个数其中两个数的和与另外一个数的异或值最大,输出这个最大值. 思路:和前面那个百度之星资格赛HDU4825的类似,多了两个过程,一个是枚举和,另一 ...
- 【Luogu】P3380树套树模板(线段树套Splay)
题目链接 幸甚至哉,歌以咏志. 拿下了曾经是那么遥不可及的线段树,学会了曾经高不可攀的平衡树,弄懂了装B的时候才挂在嘴边的树套树. 每道模板都是链上的一颗珠子.把它们挨个串起来,就成为我成长的历程. ...
- 【Luogu】P1352没有上司的舞会(树形DP)
题目链接 设f[i][0]表示第i个人不去舞会时子树的最大欢乐度,f[i][1]表示第i个人去舞会时子树的最大欢乐度. 则有状态转移方程:f[i][0]+=∑max(f[to][0],f[to][1] ...
- SPOJ LCS2 Longest Common Substring II ——后缀自动机
后缀自动机裸题 #include <cstdio> #include <cstring> #include <iostream> #include <algo ...
- SPOJ GSS2 Can you answer these queries II ——线段树
[题目分析] 线段树,好强! 首先从左往右依次扫描,线段树维护一下f[].f[i]表示从i到当前位置的和的值. 然后询问按照右端点排序,扫到一个位置,就相当于查询区间历史最值. 关于历史最值问题: 标 ...
- BZOJ 2190仪仗队【欧拉函数】
问题的唯一难点就是如何表示队长能看到的人数?如果建系,队长所在的点为(0,0)分析几组数据就一目了然了,如果队长能看到的点为(m,n),那么gcd(m,n)=1即m n 互质或者是(0,1),(1,0 ...
- 【图论】bnuoj 52810 Splitting the Empire
acm.bnu.edu.cn/v3/contest_show.php?cid=9208#problem/G [题意] 给定一个无向图,要求把这个无向图的点划分到不同的集合里,使得每个集合的点之间两两没 ...