zoukankan      html  css  js  c++  java
  • AOJ 788.数方块

    Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB
    Total Submission: 116   Submission Accepted: 38
     
    Description
    西瓜在寒假里辅导身为小学生的小西瓜寒假作业,里面有这样一道题目:
    数一数下图中有几个正方形,小巫女认为只有16个,可是老师说错了。

    对于西瓜来说,这样的问题自然很容易解决,但是现在西瓜想知道,如果现在有一个n*m个小正方形组成的长方形,请问里面一共有几个正方形呢?
    Input
    题目包含多组输入,EOF结束, 数据最多不超过100组,对于每组输入包含两个数字n,m表示现在有一个n*m个小正方形组成的大长方形,其中1<=n,m<=1000。
    Output
    对于每组输入,输出单独一行,表示大长方形中一共可以数出多少个正方形。
    Sample Input
    Original Transformed
    3 4
    4 4
    3 3
    Sample Output
    Original Transformed
    20
    30
    14

    简单的式子即可求解

    使正方形的边长为1,2,3……min(a,b)时,分别算出正方形的个数,相加即可

     1 #include <cstdio>
     2 #include <string>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <memory>
     6 #include <stack>
     7 #include <queue>
     8 #include <set>
     9 #include <algorithm>
    10 #include <map>
    11 #include <vector>
    12 using namespace std;
    13  
    14 #define debug 0
    15  
    16 /*
    17     By:OhYee
    18     Github:OhYee
    19     Email:oyohyee@oyohyee.com
    20 */
    21  
    22 int a,b;
    23 bool Do(){
    24     if(scanf("%d%d",&a,&b)==EOF)
    25         return false;
    26     int ans=0;
    27     for(int i=1;i<=a;i++)
    28         for(int j=1;j<=b;j++)
    29             if(i==j)
    30             ans+=(a-i+1)*(b-j+1);
    31     printf("%d
    ",ans);
    32  
    33 }
    34  
    35 int main(){
    36     #if debug
    37     freopen("in.txt","r",stdin);
    38     #endif
    39     while(Do());
    40     return 0;
    41 }
    /*
    By:OhYee
    Github:OhYee
    Email:oyohyee@oyohyee.com
    Blog:http://www.cnblogs.com/ohyee/
    
    かしこいかわいい?
    エリーチカ!
    要写出来Хорошо的代码哦~
    */
  • 相关阅读:
    上下伸展的JS菜单
    [ZZ]Debug VBScript with Visual Studio
    面试总结之杂题
    [ZZ]9 Confusing Naming Conventions for Beginners
    Robocopy
    [ZZ]什么是Alpha,Beta,RC,RTM,CTP版
    使用位运算交换两个值,不用临时变量
    学习笔记之编程之美微软技术面试心得(一)
    C#中如何获取系统环境变量
    学习笔记之SQL教程 from W3School
  • 原文地址:https://www.cnblogs.com/ohyee/p/5374817.html
Copyright © 2011-2022 走看看