题目描述

The recent vote in Puerto Rico favoring United States statehood has made flag makers very excited. An updated flag with 51 stars rather than the current one with 50 would cause a huge jump in U.S. flag sales. The current pattern for 50 stars is five rows of 6 stars, interlaced with four offset rows of 5 stars. The rows alternate until all stars are represented.
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
This pattern has the property that adjacent rows differ by no more than one star. We represent this star arrangement compactly by the number of stars in the first two rows: 6,5.
A 51-star flag that has the same property can have three rows of 9 stars, interlaced with three rows of 8 stars (with a compact representation of 9,8). Conversely, if a state were to leave the union, one appealing representation would be seven rows of seven stars (7,7).
A flag pattern is visually appealing if it satisfies the following conditions:
• Every other row has the same number of stars.
• Adjacent rows differ by no more than one star.
• The first row cannot have fewer stars than the second row.
Your team sees beyond the short-term change to 51 for the U.S. flag. You want to corner the market on flags for any union of three or more states. Given the number S of stars to draw on a flag, find all possible visually appealing flag patterns.

输入

The input consists of a single line containing the integer S (3 ≤ S ≤ 32,767).

输出

On the first line, print S, followed by a colon. Then, for each visually appealing flag of S stars,print its compact representation, one per line.
This list of compact representations should be printed in increasing order of the number of stars in the first row; if there are ties, print them in order of the number of stars in the second row. The cases 1-by-S and S-by-1 are trivial, so do not print those arrangements.
The compact representations must be printed in the form “x,y”, with exactly one comma between x and y and no other characters.

题目大意:输出能够组成s颗星星的所有的方案(只需要输出第一行和第二行的星星数就行)  。前提是  需要满足下列条件:

1. 星星的树木隔行相等

2.相邻两行星星  树木最多差一

3.第一行星星数要多于第二行

此外 还需满足    至少有两行星星,不能每行之有一颗星星。

思路:假设 第一行星星有n颗  则分以下三种情况讨论;

1.k*n=s   每一行都相等时 ,k表示有k行,此处的k需满足大于1

2.k*(n+n-1)=s   第一行比第二行多一颗,共有偶数行

3.k*(n+n-1)+n=s  第一行比第二行多一颗,共有奇数行

此外注意一下输出的顺序。

# include <iostream>
# include <cstdio>
#include<algorithm>
#include<string>
using namespace std;
struct node{int a;int b;
};
bool cmp(node x,node y){if(x.a==y.a){return x.b<y.b;}else return x.a<y.a;
}
int main(){int s;cin>>s;cout<<s<<':'<<endl;node q[1008611];int k=0;for(int i=2;i<=s/2;i++){if(s%i==0&&s/i!=1){q[k].a=i;q[k].b=i;k++;}}for(int i=2;(2*i-1)<=s;i++){if(s%(2*i-1)==0){q[k].a=i;q[k].b=i-1;k++;}}for(int i=2;(2*i-1)<=(s-i);i++){if((s-i)%(2*i-1)==0){q[k].a=i;q[k].b=i-1;k++;}}sort(q,q+k,cmp);for(int i=0;i<k;i++){cout<<q[i].a<<','<<q[i].b<<endl;}return 0;
}

5464: Star Arrangements相关推荐

  1. github javaguide_GitHub上收获Star数排名前10的Java项目

    1. CS-Notes star:92.1k 介绍:技术面试必备基础知识.Leetcode.计算机操作系统.计算机网络.系统设计.Java.Python.C++ :地址:https://cyc2018 ...

  2. elementui datetimepicker 移动端_在 Gitee 收获 2.5K Star,前后端分离的 RuoYi 它来了

    作为 2019 年 Gitee 上最受欢迎的开源项目,权限管理系统 RuoYi 已经在 Gitee 上获得了超过 11K 的 Star. 这次作者若依推出了基于 SpringBoot + Vue + ...

  3. 给力!斩获 GitHub 14000 Star,两周创办开源公司获数百万美元融资

    作者 | 伍杏玲 出品 | AI 科技大本营(ID:rgznai100) 上世纪 90 年代初,21 岁大学生 Linus Torvalds 开源 Linux 操作系统,自此掀起全球开源浪潮.随后&q ...

  4. 近4万Star,登月源码登顶GitHub,这位女程序员“拯救”了阿波罗

    作者 | 伍杏玲 转载自CSDN(ID:CSDNnews) 1969 年 7 月 20 日,"阿波罗 11 号"飞船登月,宇航员尼尔·阿姆斯特朗(Neil Armstrong)成功 ...

  5. GitHub超全机器学习工程师成长路线图,开源两日收获3700+Star!

    参加 2019 Python开发者日,请扫码咨询 ↑↑↑ 大会议题以及更多详情请查看:https://pythondevdays2019.csdn.net/ 作者 | 琥珀 出品 | AI科技大本营( ...

  6. 熬夜写代码,不如换女装入GitHub获上千Star?

    作者 | 琥珀 出品 | AI科技大本营(ID: rgznai100) 程序员如何以合规手段快速获得 GitHub 上千 Star? 新年刚过,GitHub Trending 上一个名为"D ...

  7. 集合70多种推荐算法,东北大学老师用Java写了一个开源库,在GitHub上收获近1500个Star...

     [AI科技大本营导读]在经过一年多的开发工作之后,LibRec 3.0 版本终于发布了.LibRec 是一个基于 Java 的开源算法工具库,覆盖了 70 余个各类型推荐算法,可以有效解决评分预测 ...

  8. 10大机器学习开源项目推荐(Github平均star为1385)

    翻译 | suisui 出品 | 人工智能头条(AI_Thinker) 本文推荐的10大机器学习开源项目是由Mybridge从250个机器学习开源项目中挑选出来的,Github 平均 star为 13 ...

  9. Python 开源项目 Top 10 精选(平均star为1128)

    翻译 | SuiSui 最近,Mybridge对250个Python开源项目进行了排名,从中精选出了Top 10.这些开源项目平均star为1128,内容包括Python新利器Pipenv, 自组织映 ...

  10. 从15000个Python开源项目中精选的Top30,Github平均star为3707,赶紧收藏!

    翻译 | AI科技大本营(ID:rgznai100) 参与 | SuiSui 继推出2017年机器学习开源项目Top 30榜单后,Mybridge AI又推出了一个Python开源项目Top 30榜单 ...

最新文章

  1. 自研芯片架构 ,这家中国公司发布DPU芯片计划
  2. c语言struct_Introduction to CSAPP(十七):复杂数据组织与C语言的 struct与union
  3. java类函数默认的保护级别_事件说明
  4. python画椭圆turtle_如何用Python画一只肥肥的柯基狗狗——turtle库绘制椭圆与弧线实践...
  5. 信息系统项目管理师优秀论文:项目整体管理
  6. 关于Matconvnet中Conv-ReLU-Pool-NormBatch的总结与思考
  7. Java网络编程----基础
  8. Linux下Socket编程的端口问题( Bind error: Address already in use )
  9. 《机器学习实战》学习笔记第二章 —— K-近邻算法
  10. Flowplayer简单酷炫的视频播放器
  11. 利用Python爬取一个百度翻译工具(初学爬虫必备)
  12. 编译 发布 release的apk
  13. 计算机六个方面的领域,计算机的应用领域分为哪六个方面
  14. 蜗牛爬井题目c语言,【3年级】40、蜗牛爬井问题
  15. Apple Pay正式入华:能否成支付宝与微信强敌
  16. csust2019集训队选拔赛题解
  17. 安装Linux详细教程
  18. HTML 渲染组件出错,这个问题可以通过安装某个缺失组件来解决。您是否想要了解详细信息? 的解决办法
  19. 2022开年第一个爆款凭什么是山东蓝翔?如何实现破圈传播?
  20. [引爆流行]Meme Engine话题(一)

热门文章

  1. python实现数模转换_树莓派:PCF8591数模转换模块的使用
  2. mysql过期数据_mysql过期数据如何删除
  3. 研究揭示人类大脑进化的基因组调控机制
  4. IDEA运行项目时停不下来
  5. Linux Mint系统常用软件安装
  6. 网络工程师常用的软件工具整理,最新软件安装包分享
  7. win10无限蓝屏_WIN10无限重启怎么解决,现在开不了机
  8. 【HCIE备考笔记】TAC报告总结
  9. 技术问答-1 跨平台
  10. Timeline调用实质