UVALive 6602 Counting Lattice Squares 【几何】【机智】

题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4613

题目大意:给你一个n*m的矩阵格子,在这n*m的矩阵格子中要你选出四个点,形成一个正方形,让正方形的面积为奇数,问可以形成多少个这样的正方形。

题目思路:从每一个奇数开始作为一个基本单元。

面积     边 能组成的正方形:

1*1      1                                                1

3*3      3 sqrt(5)                                   1+1*2

5*5      5 sqrt(17) sqrt(13)                  1+2*2

7*7      7 sqrt(37) sqrt(29) sqrt(25) 1+3*2

......

而一个m*n的正方形能构成x*x的正方形有(m-x+1)*(n-x+1)种可能性

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;

#define maxn 100005
#define LL long long
LL a[maxn];

int main ()
{
    LL m,n;
    while(~ scanf("%lld%lld",&m,&n))
    {
        if(m == 0 && n == 0) break;
        LL ans=0;
        for(LL i = 1; i <= min(m,n); i+=2) {
            ans += (m-i+1)*(n-i+1)*(i/2*2+1);
        }
        printf("%lld\n",ans);
    }
}

UVALive 6602 Counting Lattice Squares 【几何】【机智】

时间: 2024-08-19 08:17:39

UVALive 6602 Counting Lattice Squares 【几何】【机智】的相关文章

UVALive 5058 Counting BST 数学

B - Counting BST Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 5058 Description Binary Search Tree (BST) is a rooted binary tree data structure which has following properties: Left subtree conta

POJ 3090 ZOJ 2777 UVALive 3571 Visible Lattice Points(用递推比用欧拉函数更好)

题目: Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For exa

UVA Triangle Counting 11401【几何+数学】

11401 - Triangle Counting Time limit: 1.000 seconds 题意:给你n个线段,长度1-n.问可以组成多少不同的三角形 解题思路: 设最大边长为x的三角形有C(x)个,另外两条边长分别为y和z,根据三角不等式有y+z>x.所以z的范围是x-y < z < x. ①根据这个不等式,当y=1时x-1 < z < x,无解:y=2时有一个解(z=x-1):y=3时有两个解(z=x-1或者z=x-2)--直到y=x-1时有x-2个解.根据等

UVALIVE 3571 Visible Lattice Points

就欧拉函数然后地推一下. #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <st

UVALive 6527 Counting ones dfs(水

题目链接:点击打开链接 #include <cstdio> #include <vector> using namespace std; typedef long long ll; ll re; vector<int> p; void dfs(int dep, int g) { if (dep == 0) return ; if (p[dep-1] == 1) { re += (dep-1) * (1ll<< (dep-2)); re += g * (1ll

UVa1643 - Angle and Squares(几何)

有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值. 分析: 直观上来看,当这n个正方形的对角线在一条直线上时,封闭区域的面积最大.(虽然我不太会证明,=_=||) 设所有正方形边长之和为L,OA.OB两直线方程分别为:y = k1x  y = k2x,设A(x1, k1x1), B(x2, k2x2),可列出方程: ,解得,相应的就得到AB两点坐标,用叉积算出△OAB的面积再减去这些正方形面积的一半就是答案. #include<cstdio>

UVALive 6092 Catching Shade in Flatland --枚举+几何计算

题意:x=[-200,200],y=[-200,200]的平面,一天中太阳从不同角度射到长椅(原点(0,0))上,有一些树(用圆表示),问哪个时刻(分钟为单位)太阳光线与这些圆所交的弦长总和最长.太阳距离原点总是500m.(这些圆不会互相相交,每个圆都不包括原点或者不经过原点) 解法:直接暴力24*60分钟,找出此时的角度,然后求出直线方程,再枚举每个圆,求出弦长.注意这里每个圆都不包括原点,所以直线与圆的交点一定在同一侧,所以..我当时想多了,没看清题目.把他当成可以包含原点了,代码超长,幸好

HDU 1264 Counting Squares(线段树求面积的并)

Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1885    Accepted Submission(s): 946 Problem Description Your input is a series of rectangles, one per line. Each rectangle is sp

UVALive - 3263 That Nice Euler Circuit (几何)

UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址: UVALive - 3263 That Nice Euler Circuit 题意: 给出一个点,问连起来后的图形把平面分为几个区域. 分析: 欧拉定理有:设平面图的顶点数.边数.面数分别V,E,F则V+F-E=2 大白的题目,做起来还是很有技巧的. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: LA3263.cpp * C