思路:

根据案例的规律其实已经猜的差不多了,answer=n*m/2;

有一条边是1的情况,也很好判断,answer=n*m;

就是有一条边是2的时候比较隐秘:是连续2*2一块可以填,然后2*2不填,没想出总结的公式,就直接模拟了。

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
int main()
{
int cas=1,T;
int n,m;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
int ans=(n*m+1)/2;
if(n==1||m==1)
ans=n*m;
else if(n==2||m==2)
{
ans=0;
n=n*m;
while(n>8)
{
ans+=4;
n-=8;
}
if(n>=4)
ans+=4;
else
ans+=n;
}
printf("Case %d: %d\n",cas++,ans);
}
return 0;
}

lightoj1010【规律】的更多相关文章

  1. LightOJ1010---Knights in Chessboard (规律题)

    Given an m x n chessboard where you want to place chess knights. You have to find the number of maxi ...

  2. hdu1452 Happy 2004(规律+因子和+积性函数)

    Happy 2004 题意:s为2004^x的因子和,求s%29.     (题于文末) 知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en 因子 ...

  3. Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)

    传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...

  4. ACM/ICPC 之 DP解有规律的最短路问题(POJ3377)

    //POJ3377 //DP解法-解有规律的最短路问题 //Time:1157Ms Memory:12440K #include<iostream> #include<cstring ...

  5. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  6. 在sqlserver中做fibonacci(斐波那契)规律运算

    --利用sqlserver来运算斐波那契规律 --利用事物与存储过程 declare @number intdeclare @A intdeclare @B intdeclare @C int set ...

  7. 谈谈黑客攻防技术的成长规律(aullik5)

    黑莓末路 昨晚听FM里谈到了RIM这家公司,有分析师认为它需要很悲催的裁员90%,才能保证活下去.这是一个意料之中,但又有点兔死狐悲的消息.可能在不久的将来,RIM这家公司就会走到尽头,或被收购,或申 ...

  8. Math.abs(~2018),掌握规律即可!

    Math.abs(~2018) 某前端群的入门问题长姿势了,一个简单的入门问题却引发了我的思考,深深的体会到自己在学习前端技术的同时忽略遗忘了一些计算机的基础知识. 对于 JS Math对象没什么可说 ...

  9. COM中需要调用AddRef和Release的10条规律

    COM中需要调用AddRef和Release的10条规律  

随机推荐

  1. Linux C语言 网络编程(二) server模型

    前面介绍了关于连接linux服务端方式,可是服务端的资源是有限的,所以我们通常须要又一次思考,设计一套server模型来处理相应的client的请求. 第一种:并发server.通过主进程统一处理cl ...

  2. Redis3.x HA 方案(基于 Sentinel 方式)

    第一部分 Redis-HA 搭建 一.Redis-HA 拓扑 一主两从,主从复制,故障时主从切换 三个Redis节点 + Sentinel 节点 Master          127.0.0.1   ...

  3. MVC+Ext.net零基础学习记录(三)

    这里开始说明一下,如何在MVC项目中引用EXT.NET,这里参考:http://www.cnblogs.com/zhanghaomars/p/3470987.html

  4. MVC+Ext.net零基础学习记录(二)

    很多人在开发一个新的项目时,需要先决定项目的整体架构,是决定使用MVC的同时也不例外,具体包含:项目的多语言性,项目的多风格选择,项目的可扩展性 其中项目的多语言性:http://www.cnblog ...

  5. linux内核中创建线程方法【转】

    本文转载自:https://www.cnblogs.com/Ph-one/p/6077787.html 1.头文件 #include <linux/sched.h> //wake_up_p ...

  6. JavaScript多态

    function Master(){ //给动物喂食 this.feed=function(animal,food){ window.alert(animal.constructor); docume ...

  7. canvas刮刮卡

    <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...

  8. OpenCv-Python 图像处理基本操作

    1. 图片加载.显示和保存 import cv2 img = cv2.imread("01.jpg") imgGrey = cv2.imread("01.jpg" ...

  9. 【面试题046】求1+2+...+n

    [面试题046]求1+2+...+n 题目:     求1+2+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C).   思 ...

  10. nginx使用ssl模块配置HTTPS支持 <转>

    默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中.通常这 ...