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] ...
随机推荐
- Any Way You Slice It (向量旋转 以及 判断线段是否相交)(模板)
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11353 #include<iostream> # ...
- SQL Server 和 Oracle 以及 MySQL 有哪些区别?
SQL,在这里我理解成SQL Server.三者是目前市场占有率最高(依安装量而非收入)的关系数据库,而且很有代表性.排行第四的DB2(属IBM公司),与Oracle的定位和架构非常相似,就不赘述了. ...
- BeanFactory和FactoryBean
BeanFactory和FactoryBean 1.BeanFactory BeanFactory定义了 IOC 容器的最基本形式,并提供了 IOC 容器应遵守的的最基本的接口,也就是Spring I ...
- 内存泄露 memory leak 的原因
#include <iostream> using namespace std; void foo() { MyClass *x; x = new MyClass(); //指向的丢失了 ...
- 关于Java中try-catch-finally-return语句的思考
我们知道return语句用在某一个方法中,一是用于返回函数的执行结果,二是用于返回值为void类型的函数中,仅仅是一个return语句(return ;),此时用于结束方法的执行,也即此return后 ...
- hdu 4655 Cut Pieces
这个解题报告讲的很详细了!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #in ...
- 【无聊放个模板系列】BZOJ 3172 (AC自动机)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- 拒绝卡顿——在WPF中使用多线程更新UI
原文:拒绝卡顿--在WPF中使用多线程更新UI 有经验的程序员们都知道:不能在UI线程上进行耗时操作,那样会造成界面卡顿,如下就是一个简单的示例: public partial class MainW ...
- JS选中OPTION
var obj_prov = document.getElementById("prov"); var prov_text = obj_prov.options[obj_prov. ...
- Android 通过 Intent 传递类对象
Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...