HDU 4627 The Unsolvable Problem 2013 Multi-University Training Contest 3
给你一个数 n ( 2 <= n <= 109 ),现在需要你找到一对数a, b (a + b = n),并且使得LCM(a, b)尽可能的大,然后输出最大的 LCM(a, b)。
(为什么我每次看到题目都想去暴力。。Orz 题外话)
这道题先对 n = 2 的情况进行判断,从输出可以知道 n = 2 的时候 ans = 1。接着对 n 进行分情况讨论。当 n = 2k + 1 的时候,ans = k * (k + 1)。
当 n = 2k 的时候:
当 k 为偶数的时候 ans = (k + 1) * (k - 1)
当 k 为奇数的时候 ans = (k + 2) * (k - 2)
P.S : 杭电给的解题报告写反了。。Orz
这道题目的定位是签到题,就不多说了。
附AC代码:
1: #include <stdio.h>
2: #include <math.h>
3: #include <iostream>
4: #include <cstdarg>
5: #include <algorithm>
6: #include <string.h>
7: #include <stdlib.h>
8: #include <string>
9: #include <list>
10: #include <vector>
11: #include <map>
12: #define LL __int64
13: #define M(a) memset(a, 0, sizeof(a))
14: using namespace std;
15:
16: void Clean(int count, ...)
17: {
18: va_list arg_ptr;
19: va_start (arg_ptr, count);
20: for (int i = 0; i < count; i++)
21: M(va_arg(arg_ptr, int*));
22: va_end(arg_ptr);
23: }
24:
25: int main()
26: {
27: LL T;
28: cin >> T;
29: while (T--)
30: {
31: LL n;
32: cin >> n;
33: LL i = n / 2;
34: if (n == 2) cout << 1 << endl;
35: else if (n % 2) cout << (i * (i + 1)) << endl;
36: else if (i % 2) cout << ((i - 2) * (i + 2)) << endl;
37: else cout << ((i - 1) * (i + 1)) << endl;
38: }
39: return 0;
40: }
HDU 4627 The Unsolvable Problem 2013 Multi-University Training Contest 3的更多相关文章
- hdu 4627 The Unsolvable Problem【hdu2013多校3签到】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Problem Time Limit: 2000/1000 MS ( ...
- hdu 4627 The Unsolvable Problem(暴力的搜索)
Problem Description There are many unsolvable problem in the world.It could be about one or about ze ...
- hdu 4627 The Unsolvable Problem
http://acm.hdu.edu.cn/showproblem.php?pid=4627 分类讨论一下就可以 代码: #include<iostream> #include<cs ...
- HDU 4627 The Unsolvable Problem(简单题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 题目大意:给定一个整数n(2 <= n <= 109),满足a+b=n并且[a,b] ...
- HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题
题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...
- HDU 6141 - I am your Father! | 2017 Multi-University Training Contest 8
思路来自 FXXL 最小树形图模板用kuangbin的 /* HDU 6141 - I am your Father! [ 最小树形图 ] | 2017 Multi-University Traini ...
- HDU 5775 Bubble Sort(线段树)(2016 Multi-University Training Contest 4 1012)
原址地址:http://ibupu.link/?id=31 Problem Description P is a permutation of the integers from 1 to N(ind ...
- hdu 6406 Taotao Picks Apples (2018 Multi-University Training Contest 8 1010)(二分,前缀和)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6406 思路: 暴力,预处理三个前缀和:[1,n]桃子会被摘掉,1到当前点的最大值,1到当前点被摘掉的桃子的 ...
- HDU 4946 Area of Mushroom(2014 Multi-University Training Contest 8)
思路: 只有速度最大才有可能为1,速度不是最大肯定为0,那么就是 只需要操作那些速度最大的点,这些点求一个凸包,判断一下是不是在凸包边上即可. 有几个需要注意的地方: 1.最大速度如果为0 那么肯 ...
随机推荐
- ExtJS之Ext.getDom
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- js的正则表达式
正则表达式(regular expression)是一中描述字符模式的对象,js的RegExp类表示正则表达式,String与RegExp都定义了相应的方法来操作正则表达式,比如模式匹配,文本检索和替 ...
- 【hdu3341-Lost's revenge】DP压缩+AC自动机
题意:给定只含有A.G.C.T的n个模板串,一个文本串,文本串任意两个字母可互换位置,问最多能匹配多少个模板串.注意:匹配同一个模板串匹配了两次,ans+=2:(可重复) 题解: 原本想到一个简单dp ...
- 使用RockMongo管理MongoDB
http://blog.csdn.net/mydeman/article/details/7082730
- 8天学通MongoDB——第二天 细说增删查改
原文地址:http://www.cnblogs.com/huangxincheng/archive/2012/02/19/2357846.html 看过上一篇,相信大家都会知道如何开启mongodb了 ...
- 2016CVTE编程题:兔子藏洞
兔子藏洞 题目描述 一只兔子藏身于20个圆形排列的洞中(洞从1开始编号),一只狼从x号洞开始找,下次隔一个洞找(及在x+2号洞找),在下次个两个洞找(及在x+5号洞找),以此类推...它找了n次仍然没 ...
- TableViewCell自定义分割线
产品设计的要求cell的分割线长度不用是整个屏幕宽,并且设计要求分割线为2px(两条),上下不同色. 实现如下: UITableView中将分割线样式改为None tableView.separato ...
- 对QT的理解——能在公司里不做Java,不做很偏门的产品,不使用偏门的语言,还有钱挣,要有感恩的心
我的理解: QT做应用软件可以很强大,界面足够漂亮(最有意思的是QSS,让我刮目相看),应该是足够了.同时QT也提供了源码,不过超级复杂,难以理解,所以还是无法深入底层.另外它提供了一个额外的好处,就 ...
- 使用Intellij IDEA从零使用Spring MVC
原文:使用Intellij IDEA从零使用Spring MVC 使用Intellij IDEA从零使用Spring MVC 黑了Java这么多年, 今天为Java写一篇文章吧. 这篇文章主要是想帮助 ...
- 【Spring开发】—— Spring Core
原文:[Spring开发]-- Spring Core 前言 最近由于一些工作的需要,还有自己知识的匮乏再次翻开spring.正好整理了一下相关的知识,弥补了之前对spring的一些错误认知.这一次学 ...