【CodeForces - 215C 】Crosses (思维,图形题)

题干:

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 ≤ mholds). 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 the n × 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 %I64d specifier.

Examples

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).

题目大意:

   给你两个关系,(可以认为代表两个矩形,这很关键)。问你满足条件的六元组个数有多少个?

解题报告:

   不错的一个思维题。反正让我自己想是想不出来的、、、

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int n,m,s,r;
__int64 f(int h,int w) {return (n - h + 1) * (m - w + 1 );
}
__int64 ans;
int main() 
{scanf("%d%d%d",&n,&m,&s);for(int i = 1; i <= n; i += 2) {for(int j = 1; j <= m; j += 2) {r=s-i*j;if(r == 0) {ans +=((i + 1) * (j + 1) / 2 - 1) * f(i,j);}else if(r > 0) {for(int k = 1; k < j; k += 2) {if((r%2==0) &&(r/2)%k == 0 && i + r/k <= n) ans += 2*f(i+r/k,j);}}}}printf("%I64d\n",ans);return 0;
}

总结:根据gy学长给的公式,,最后那个if判断那里可以直接写成if(r%(2*k) == 0 && i+r/k <= n)。

官方题解:

#include <cstdio>
int n,m,s,r;
//2 equations represents 2 rectangles!!!
//so we enumerate one rectangle's hight and width//how many rectangle with h and m are there in the big given rectangle
__int64 f(int h,int w){ return (n - h + 1) * (m - w + 1 );}
__int64 ans;
int main(){scanf("%d%d%d",&n,&m,&s);ans = 0;for(int i = 1; i <= n; i += 2){//enumerate hightfor(int j = 1; j <= m && (r = s - i * j) >= 0; j += 2){if(r == 0){//one rectangle is fairly enough//suppose (a,b) must be i,j//then (c,d) can have (i + 1)/2 * (j + 1)/2 choices//then (a,b) and (c,d) can exchange, so we * 2//but if(a,b) and (c,d) are the same,exchange them does not make any difference//that is when a = c = i, b = d = jans +=( (i + 1) * (j + 1) / 2 - 1) * f(i,j);}elsefor(int k = 1; k < j; k += 2)if(r % (2 * k) == 0 && i + r / k <= n)ans += 2 * f(i + r / k, j);// (a,b) and (c,d) can exchange}}printf("%I64d\n",ans);return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441305.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Scaffold php,GitHub - yiiplus/scaffold: scaffold是一个基于Yii2高级项目模版工程化实现的应用程序...

Yii 2 Scaffold Project Kit易加-脚手架(scaffold)是一个基于Yii2高级项目模版工程化实现的应用程序&#xff0c;它将更加高效、规范和工程化的满足项目开发的需求。DIRECTORY STRUCTUREcommonconfig/ contains shared configurationsmail/ contains view files for e-mailsmod…

oracle修改某个数据类型,Oracle 修改某个字段的数据类型三种方式

1.将该列设置为null,再修改其类型(这样会丢失数据)2.最简单的方法&#xff1a;假设你的表名为 tab_targetcreate table test as select * from tab_target whre 12;alter table test modify (col_name number(5));insert into test select * from tab_target;drop table tab_t…

【EOJ Monthly 2018.10 - B】 莫干山奇遇 (思维构造,数学,数组,贪心)(总结)

题干&#xff1a; Time limit per test: 2.0 seconds Memory limit: 512 megabytes 出题人当然是希望出的题目有关 oxx&#xff0c;于是想方设法给题目配上一些有关 oxx 的背景故事&#xff0c;使得它看起来不那么无趣。但有的时候却无法引入合适的小姐姐&#xff0c;使得 o…

有奶瓶的linux系统,用U盘启动BEINI(奶瓶)系统

用U盘启动&#xff1a;奶瓶(beini)这个系统&#xff0c;是一款基于Tiny Core Linux 搭建的无线网络安全测试系统&#xff0c;当然由于它是用来安全测试的系统&#xff0c;因此在安全方面自然有着强大的功能。而且&#xff0c;这个系统非常简便易学&#xff0c;因此现在已经逐渐…

【CodeForces - 227A】Where do I Turn? (计算几何,叉积判断直线拐向)

题干&#xff1a; Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point C and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from…

linux内核镜像sd卡,【原创】Linux QT镜像的制作--制作SD卡启动盘

最近买了个新的开发板&#xff0c;原生的是Android操作系统&#xff0c;需要自己少个启动盘&#xff0c;制作LinuxQT操作系统。新的开发板带这个制作的源文件&#xff0c;要先把这个文件拷贝到虚拟机Ubunbtu的共享目录下。打开share文件下显示文件如下&#xff1a;打开文件夹命…

【CodeForces - 227C】Flying Saucer Segments (思维)

题干&#xff1a; An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives dont even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, consists of three sections. …

清楚linux缓存文件,Linux删除文件 清除缓存

相信很多测试 经常会经历开发叫你清除缓存这种事。那我们要怎么清呢&#xff1f;一、首先&#xff0c;确认你要清除的缓存在哪个目录下&#xff0c;然后切换到该目录下&#xff0c;比如 我现在知道我的的缓存目录是在newerp这个目录下&#xff0c;则如图二、然后 执行命令 rm -…

win10 linux安卓模拟器,genymotion安卓模拟器在Window10中使用的问题

最近一段时间&#xff0c;把系统升级到了win10&#xff0c;然后悲催的事情出现了&#xff0c;genymotion挂了&#xff0c;根本就不能启动&#xff0c;而且还是2.6版本的genymotion&#xff0c;下面我把遇到的问题总结一下&#xff1a;首先&#xff0c;在我的win10系统中&#x…

cross_compile = arm-linux-,cross compile grpc for arm

8种机械键盘轴体对比本人程序员&#xff0c;要买一个写代码的键盘&#xff0c;请问红轴和茶轴怎么选&#xff1f;This post will tell you how to cross compile gPRC static lib for ARM.前段时间尝试交叉编译gRPC遇到了不少的麻烦&#xff0c;写篇post记录一下。gRPCPreparat…

linux键盘映射默认,Linux 中的键盘映射

前面提到&#xff0c;X Window 直接处理了键盘的输入输出端口&#xff0c;因此&#xff0c;在 Linux 虚拟控制台下和 X Window 下使用不同的键盘映射方法。在 Lin对于英语来说&#xff0c;键盘上的字母键直接和英语字母表中的字母对应&#xff0c;但是对于非英语的语种来说&…

C语言用字符串sex储存,2005年计算机等级考试二级C语言全真标准预测试卷(2)

一、选择题(1&#xff5e;40题每题1分&#xff0c;41&#xff5e;50题每题2分&#xff0c;共60分)1.微型计算机的运算器、控制器及内存储器组合在一起&#xff0c;称之为()(本题分值&#xff1a;1分)A.ALUB.CPUC.MPUD.主机【正确答案】D2.下列存储器中&#xff0c;存取速度最快…

c语言全局变量SQR,c语言a/=SQR(k+m);是什么意思?

满意答案NightmareJJ2013.03.16采纳率&#xff1a;47% 等级&#xff1a;12已帮助&#xff1a;11233人先看第一个main() // 主函数{printf("%ld\n", fun(3));} //输出fun(3)这个函数的返回值&#xff0c;3就是下一个//函数中的n 值。long fun (int n) //定义fun函数…

【POJ - 1850】Code (组合数学,字符串另类排序)

题干&#xff1a; Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is that one where a number is associated to a character sequence. It is considered that …

c语言蓝牙接收6,终于搞定了通过两路蓝牙接收数据

一直想做无线传感器&#xff0c;通过蓝牙来接收数据&#xff0c;无奈因为arduino接收串口数据的一些问题&#xff0c;一直搁到现在。因为学校里给学生开了选修课&#xff0c;所以手边有一些nano和mega可以使用&#xff0c;所以就做了用两个nano加上两个蓝牙模块来发射数据&…

【POJ - 1942 】Paths on a Grid (组合数学,求组合数的无数种方法)

题干&#xff1a; Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time hes explaining that (ab) 2a 22abb 2). So you decide to waste your time with d…

兔子吃萝卜的c语言编程,狼追兔子的c语言实现

满意答案16guoyuming2013.03.05采纳率&#xff1a;49% 等级&#xff1a;13已帮助&#xff1a;8005人用单链表实现#include #includetypedef struct node{int cave;struct node * next;}node,*LinkList;void main(){int i0,j,count1; // 初始值为1&#xff1b;LinkList L,p,h…

android 动态换肤框架,GitHub - ss520k/Android-Skin-Loader: 一个通过动态加载本地皮肤包进行换肤的皮肤框架...

Android-Skin-Loader更新日志导入到Android Studio&#xff0c;使用gradle构建皮肤包(见7. 皮肤包是什么&#xff1f;如何生成&#xff1f;)(2015-12-02)解决Fragment换肤在某些版本的support-v4包下失效的问题(感谢javake同学)(2015-12-02)对textColor加入selector类型的资源的…

android吸附菜单,Android仿微博、人人Feed详情页吸附导航栏

仿微博、人人的feed详情页面&#xff1a;Listview上下滑动&#xff0c;导航栏view可吸附在顶部的效果。一、实现效果上图&#xff1a;效果图.gif欢迎拍砖&#xff0c;拍拍更进步。没有对比&#xff0c;怎么会有伤害&#xff0c;下面是 微博、人人的Feed详情页&#xff1a;微博、…

android 居右属性,使用layoutDirection属性设置布局靠左或靠右

通过设置layoutDirection属性值为mx.core.LayoutDirection.RTL(右到左)或mx.core.LayoutDirection.LTR(左到右)&#xff0c;使布局为靠左或靠右(如下图)。该属性可设置3种值&#xff0c;LayoutDirection.RTL、LayoutDirection.LTR和null(ILayoutDirectionElement时)/undefined(…