zoukankan      html  css  js  c++  java
  • Codeforces Round #645 (Div. 2) A. Park Lighting

    Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.

    The park is a rectangular table with nn rows and mm columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 11. For example, park with n=m=2n=m=2 has 1212 streets.

    You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).

    The park sizes are: n=4n=4, m=5m=5. The lighted squares are marked yellow. Please note that all streets have length 11. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.

    Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.

    Input

    The first line contains a single integer tt (1t1041≤t≤104) — the number of test cases in the input. Then tt test cases follow.

    Each test case is a line containing two integers nn, mm (1n,m1041≤n,m≤104) — park sizes.

    Output

    Print tt answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.

    Example
    Input
    Copy
    5
    1 1
    1 3
    2 2
    3 3
    5 3
    
    Output
    Copy
    1
    2
    2
    5
    8
    只会分类讨论的垃圾解法==
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int n,m;
            cin>>n>>m;
            if(n%2==0)
            {
                cout<<m*(n/2)<<endl;
            }
            else if(m%2==0)
            {
                cout<<n*(m/2)<<endl;
            }
            else
            {
                cout<<m*(n/2)+m/2+1<<endl;
            }
        }
    }
  • 相关阅读:
    软件工程概论之web基础
    java动手动脑——异常处理
    Java动手动脑——多态和继承
    java字串
    数据结构——用栈来判断回文字符串
    java一个能记录生成多少个对象的类
    openwrt设置默认登陆密码
    在ubuntu中安装luci解决iwinfo.h No such file or directory问题
    添加mysamba
    更改默认打开wifi功能
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12970539.html
Copyright © 2011-2022 走看看