lightoj 1014
判断到根号n即可,另外使用dfs输出,不需要另开数组再排序。
#include<cmath>
#include<cstdio>
int P, L, len, cnt;
void dfs(int dep){
if(dep > len) return;
if(dep > L){
if(P % dep == 0){
if(cnt == 1) printf("%d", dep), cnt = 2;
else printf(" %d", dep);
dfs(dep+1);
if(P/dep != dep && P/dep > L) {
if(cnt == 1) printf(" %d", P/dep), cnt = 2;
else printf(" %d", P/dep);
}
}else dfs(dep+1);
}else {
dfs(dep+1);
if(P % dep == 0 && P/dep > L) {
if(cnt == 1) printf("%d", P/dep), cnt = 2;
else printf(" %d", P/dep);
}
}
}
int main(){
int t, CASE(0);
scanf("%d", &t);
while(t--){
scanf("%d%d", &P, &L);
if(L >= P - L) printf("Case %d: impossible\n", ++CASE);
else {
P -= L;
len = sqrt(P);
printf("Case %d: ", ++CASE);
cnt = 1;
dfs(1);
printf("\n");
}
}
lightoj 1014的更多相关文章
- Lightoj 1014 - Ifter Party
I have an Ifter party at the 5th day of Ramadan for the contestants. For this reason I have invited ...
- Ifter Party LightOJ - 1014(水题)
题意:有C个人,给P个食物,每人吃Q个,剩L个.然后给你P和L(Q>L),让你求Q的可能情况,如果有多种可能,从小到大输出:如果不存在,输出impossible 就是求写出公式 遍历c求P-L的 ...
- LightOJ 1236 - Pairs Forming LCM(素因子分解)
B - Pairs Forming LCM Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS Memor ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)
Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...
- 1014: [JSOI2008]火星人prefix
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ 1014: [JSOI2008]火星人prefix [splay 二分+hash] 【未完】
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6243 Solved: 2007[Submit] ...
随机推荐
- 动态设置uitableview高度,参考
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // ...
- (转)Linux 文件系统:procfs, sysfs, debugfs 用法简介
网址:http://www.tinylab.org/show-the-usage-of-procfs-sysfs-debugfs/ 1 前言 内核中有三个常用的伪文件系统:procfs,debugfs ...
- ServiceStack.Redis
什么是Redis 首先,简述一下什么是Redis. Redis是一个开源.支持网络.基于内存.键值对存储数据库,使用ANSI C编写.从2013年5月开始,Redis的开发由Pivotal赞助.在这之 ...
- 团体程序设计天梯赛-练习集L1-009. *N个数求和
L1-009. N个数求和 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 本题的要求很简单,就是求N个数字的和.麻烦的是,这些 ...
- KafkaSpout: PartitionManager的行为分析
KafkaSpout的核心逻辑都是由PartitionManager来实现的. 但是这个类实现时候需要考虑的东西有些多,0.92至0.93,至当前(2015.3.14)的master一直在变化.在这里 ...
- 【leetcode】4Sum(middle)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- HDU1411+四面体的体积
用cos sin各种乱搞之后 求出一个公式.. 但是怕精度损失厉害,还是暂且贴个公式的,copy别人的.. #include<stdio.h> #include<math.h> ...
- linux mysql为root用户初始化密码和改变root密码
初始化密码: 由于安装MySQL完后,MySQL会自动提供一个不带密码的root用户,为了安全起见给root设置密码: #mysqladmin -u root password 123 (123为密码 ...
- linux的终端,网络虚拟终端,伪终端(转)
blog.csdn.net/todd911/article/details/8025540 Linux上许多网络服务应用,如l2tp.pptp.telnet,都用到了伪终端.有朋友在问这方面的概念 ...
- SSH应该使用密钥还是密码?
关于SSH,几乎每个人都同意密钥要优于密码,更安全,并且更先进,但我并不同意这个观点. 虽然密钥的确可以更好,但它有着还没被意识到的严重风险,并且我认为比得到妥善管理的密码更不安全. 通常密钥更好的理 ...