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] ...
随机推荐
- NBTSTAT命令详解
1. 具体功能 该命令用于显示本地计算机和远程计算机的基于 TCP/IP(NetBT) 协议的 NetBIOS 统计资料. NetBIOS 名称表和 NetBIOS 名称缓存. NBTSTAT ...
- iOS5编程--ARC在工程上的相关设置
在创建工程的时候,我们可以指定工程是否使用ARC技术,如下图 选中表示支持ARC, 在Beta5以前的版本中,不提供这个选项,非常麻烦. 如果是你拿到的工程,那么可以通过设置来改变,如下图所示 如果不 ...
- ExtJs4.2 知识点
知识点1:修改密码类 参考:点击这里 Ext.apply(Ext.form.VTypes, { password: function (val, field) { if (field.initialP ...
- Any Way You Slice It (向量旋转 以及 判断线段是否相交)(模板)
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11353 #include<iostream> # ...
- asp.net MVC日志插件Log4Net学习笔记一:保存日志到本地
log4net(Log For Net)是Apache开源的应用于.Net框架的日志记录工具,详细信息参见Apache网站.它是针对Java的log4j(Log For Java的)姊妹工具.用过lo ...
- List<T> 排序
List<T>的排序 List<DataPoint> dataPointsDataPints = ...; //按RegisterAddress升序排序 dataPointsD ...
- 中国首个 SaaS 模式的云告警平台安卓版 APP 上线
今年一月底,国内首个 SaaS 模式的云告警平台 OneAlert 正式发布了 iOS 版 App 客户端,今天上午,安卓版 App 客户端也正式上线了!每个安卓用户,无需电脑,都可以通过手机全程跟踪 ...
- 李洪强iOS开发本人集成环信的经验总结_03_注册
李洪强iOS开发本人集成环信的经验总结_03_注册 环信一共提供了三种注册的方法: 01 同步注册: 02 异步注册: 03 - 使用代理回调进行注册,但是3.0没有了,3.0之前有 调用注册 ...
- nginx做负载均衡配置文件
nginx做负载均衡是在反向代理的基础上做的,代码如下: ## Basic reverse proxy server ## ## Apache backend for www.baidu.com ## ...
- PHP 简单的加密解密算法
<?php /** * * @创建时间:2015-3-12 下午2:07:33 * @作者:YuMing * @描述:异或加密解密类 */ class Yihuo extends CI_Cont ...