cf 189B

题目:189B - Counting Rhombi http://codeforces.com/problemset/problem/189/B

题意:给定一个长方形的 矩形,求能在这个矩形里有多少 对角线跟坐标垂直的菱形

思路:枚举这个菱形的中心的那一个点,然后找这个点 离边界比较小的那一个距离

这样利用 中心点和 两条对角线就可以确定一个菱形,每个点枚举。。。

心得:要解析一下图形的 结构 构成

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 
 6 int __min(int a,int b)
 7 {
 8   return a>b?b:a;
 9 }
10 int main()
11 {
12     int w,h;
13     int i,j;
14     long long sum;
15     while(cin>>w>>h)
16     {
17         sum=0;
18         for(i=1; i<=w; i++)//枚举点
19         for(j=1; j<=h; j++)//枚举点
20         sum+=__min(i,w-i)*__min(j,h-j);//相当于枚举边。。
21 
22         cout<<sum<<endl;
23     }
24     return 0;
25 }
原文地址:https://www.cnblogs.com/bfshm/p/3485442.html