CodeForces - 50A Domino piling (贪心+递归)

题意分析

奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0。

代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define INF 0x3f3f3f3f
#define nmax 200
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
int n,m;
int solve(int n,int m)
{
if(n ==1 && m == 1) return 0;
if(n%2 == 0) return n/2 * m;
else if( m%2 ==0) return m/2 *n;
else{
if(n>=m) return solve(n-1,m) + solve(1,m);
else return solve(n,m-1) + solve(n,1);
}
}
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m) != EOF){
printf("%d\n",solve(n,m));
}
return 0;
}

CodeForces - 50A Domino piling (贪心+递归)的更多相关文章

  1. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  2. codeforces水题100道 第三题 Codeforces Beta Round #47 A. Domino piling (math)

    题目链接:http://www.codeforces.com/problemset/problem/50/A题意:一个NxM的举行中最多能放多少个1x2的矩形.C++代码: #include < ...

  3. Codeforces 161 B. Discounts (贪心)

    题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...

  4. CodeForces 176A Trading Business 贪心

    Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...

  5. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  6. <算法竞赛入门经典> 第8章 贪心+递归+分治总结

    虽然都是算法基础,不过做了之后还是感觉有长进的,前期基础不打好后面学得很艰难的,现在才慢慢明白这个道理. 闲话少说,上VOJ上的专题训练吧:http://acm.hust.edu.cn/vjudge/ ...

  7. Codeforces 486C Palindrome Transformation(贪心)

    题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要 ...

  8. Codeforces 1154D - Walking Robot - [贪心]

    题目链接:https://codeforces.com/contest/1154/problem/D 题解: 贪心思路,没有太阳的时候,优先用可充电电池走,万不得已才用普通电池走.有太阳的时候,如果可 ...

  9. codeforces 735C Tennis Championship(贪心+递推)

    Tennis Championship 题目链接:http://codeforces.com/problemset/problem/735/C ——每天在线,欢迎留言谈论. 题目大意: 给你一个 n ...

随机推荐

  1. facebook原生广告添加adchoice图标

    1.在需要显示adchoice的地方添加一个textview: <LinearLayout android:id="@+id/ad_ic_action" android:la ...

  2. windows安装logstash-input-jdbc并使用其导入MMSQL数据

    1.安装logstash 2.修改logstash 文件夹下Gemfile文件 将source改为:https://gems.ruby-china.org 3.进入bin目录 执行logstash-p ...

  3. 【二】H.264/MPEG-4 Part 10 White Paper 翻译之 Prediction of Intra Macroblocks

    翻译版权所有,转载请注明出处~ xzrch@2018.09.14 ------------------------------------------------------------------- ...

  4. 「日常温习」Hungary算法解决二分图相关问题

    前言 二分图的重点在于建模.以下的题目大家可以清晰的看出来这一点.代码相似度很高,但是思路基本上是各不相同. 题目 HDU 1179 Ollivanders: Makers of Fine Wands ...

  5. hdu1061Rightmost Digit(快速幂取余)

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. spring boot 中文乱码问题

    在刚接触spring boot 2.0的时候,遇到了一些中文乱码的问题,网上找了一些解决方法. 这里自己做个汇总. 在application.properties文件中添加: spring.http. ...

  7. HDU 3260/POJ 3827 Facer is learning to swim(DP+搜索)(2009 Asia Ningbo Regional)

    Description Facer is addicted to a game called "Tidy is learning to swim". But he finds it ...

  8. C语言文件基本操作

    1.用文本方式储存‘1’,‘0’,‘2’存入文件,然后用二进制方式从文件开头读出一个short型数据,并验证结果是否正确 #include<stdio.h> #include<str ...

  9. Code obfuscatio (翻译!)

    Description Kostya likes Codeforces contests very much. However, he is very disappointed that his so ...

  10. iOS开发NSDate详解

    1. 用于创建NSDate实例的类方法有 + (id)date; 返回当前时间 + (id)dateWithTimeIntervalSinceNow:(NSTimeInterval)secs; 返回以 ...