CSU 1558 和与积
来源:互联网 发布:淘宝客服招聘上海 编辑:程序博客网 时间:2024/06/04 18:21
CSU 1558 和与积
Time Limit: 1 Sec Memory Limit: 128 MB Special Judge
Submit: 121 Solved: 69
Description
构造N个正数(每个数不超过1000000),使所有数的和与所有数的积相差刚好等于D,按非递减序输出。
Input
多组测试数据(不超过1000组),每行两个正整数N和D。(2<=N<=1000,D<=1000)
Output
每行应该按非递减序输出对应的N个数。
Sample Input
2 1
3 5
Sample Output
2 3
1 2 8
/** 不知道为什么,这道题连别人给的AC的代码* 都过不了,简直无解。* 秘制WA,玄学啊 */// 规律版#include <iostream>#include <cstdio>using namespace std;int main() { int N, D; while(scanf("%d%d", &N, &D) != EOF) { for(int i = 0; i < N - 2; i++) { printf("1 "); } printf("2 %d\n", N + D); } return 0;}
/** 不知道为什么,这道题连别人给的AC的代码* 都过不了,简直无解。* 秘制WA,玄学啊 */// 这个是组合版的,测试了几十组数据// 全部和前面那个规律版一样// 但是因为规律版也秘制WA// 所以我也不知道这程序对不对#include <iostream>#include <cstdio>using namespace std;const int MAX_NUM = 1000 + 5;int N, D;int rcd[MAX_NUM];bool select_combination(int l, int p, int plu, int mult) { if(l == N) { if(mult - plu == D) { for(int i = 0; i < N; i++) { printf("%d", rcd[i]); if(i < N - 1) { printf(" "); } } printf("\n"); return true; } return false; } for(int i = p - 1; i < 1000000; i++) { rcd[l] = i; if(select_combination(l + 1, i + 1, plu + i, mult * i)) { return true; } }}int main(){ while(scanf("%d%d", &N, &D) != EOF) { select_combination(0, 2, 0, 1); } return 0;}
0 0
- CSU 1558 和与积
- CSU 1558 和与积
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- Android各种动画插值器的实例
- 计算几何模板
- Fragment加动画后快速点击屏幕进行切换 产生的异常: java.lang.IllegalStateException: No host
- GetModuleHandle,AfxGetInstanceHandle使用区别
- eclipse的常用快捷键
- CSU 1558 和与积
- UVA445 - Marvelous Mazes
- Algorithm Gossip: Eratosthenes筛选求质数
- RequireJS 2.x —— 基础使用
- ZenGl跨平台图形引擎介绍
- MFC消息映射与命令传递
- WOJ1006 - Language of Animals
- 图解Oracle 12c创建数据挖掘(Data Miner)用户dmuser
- K-means算法-机器学习入门