Given three integers n(1≤n≤1018), m(1≤m≤105), k(1≤k≤1018).
you should find a list of integer A1,A2,…,Am which
satisfies three conditions:

1. A1+A2+⋯+Am=n.

2. 1≤Ai≤k−1 for
each (1≤i≤m).

3. GCD(A1,A2,…,Am)=1.GCD
means the greatest common divisor

4. if i<j then Ai≥Aj.

As the author is too lazy to write a special judge, if there's no answer ouput "I love ACM", And if there's more than one answer, output the one has the minimum A1,
and if there still multiple answer make theA2 as
small as possible, then A3,A4…

m=1  直接 “I love ACM”

m=2

均摊 第二个给第一个不断给1

m=3

均摊 最后一个给第一个1个1

很多边界数据注意下

3 3 1

1 1 1

1 1 4

等等..

代码如下:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
using namespace std;
long long n,m,k;
long long gcd(long long a,long long b)
{
long long r;
while(b>0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
long long A[100000+5];
void do1()
{
if(n%2==1)
{
long long p=n/2+1;
if(p<=k-1) printf("%lld %lld\n",p,p-1);
else printf("I love ACM\n");
}
else
{
int ok=1;
long long a=n/2,b=n/2;
while(a+1<=k-1&&b-1>=1)
{
a++;
b--;
if(gcd(a,b)==1)
{
ok=0;
printf("%lld %lld\n",a,b);
break;
}
}
if(ok)
printf("I love ACM\n");
}
}
void do2()
{
memset(A,0,sizeof(A));
for(int i=1;i<=m;i++)
{
A[i]=n/m;
}
for(int i=1;i<=n%m;i++)
{
A[i]++;
}
if(n%m==0&&n!=m)
{
A[1]++;A[m]--;
}
if(A[1]<=k-1&&A[m]>=1)
{
for(int i=1;i<=m;i++)
{
printf("%lld",A[i]);
if(i!=m) printf(" ");
}
printf("\n");
}
else printf("I love ACM\n");
}
int main()
{
while(cin>>n>>m>>k)
{
if(m==1&&n!=1||k==1) printf("I love ACM\n");
else if(m==1&&n==1) printf("1\n");
else
{
if(m==2) do1();
else if(m>=3) do2();
}
}
}

【贪心】【TOJ4107】【A simple problem】的更多相关文章

  1. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  2. POJ 3468 A Simple Problem with Integers(线段树/区间更新)

    题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS     Memory Limit: 131072K Description Yo ...

  3. poj 3468:A Simple Problem with Integers(线段树,区间修改求和)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 58269   ...

  4. ACM: A Simple Problem with Integers 解题报告-线段树

    A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...

  5. poj3468 A Simple Problem with Integers (线段树区间最大值)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92127   ...

  6. POJ3648 A Simple Problem with Integers(线段树之成段更新。入门题)

    A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Acc ...

  7. BZOJ-3212 Pku3468 A Simple Problem with Integers 裸线段树区间维护查询

    3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Sol ...

  8. POJ 3468 A Simple Problem with Integers(线段树区间更新区间查询)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92632   ...

  9. A Simple Problem with Integers(树状数组HDU4267)

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...

  10. A Simple Problem with Integers

    A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 77964 Acc ...

随机推荐

  1. 《Qt编程的艺术》——5.1 手动布局

    在传统的GUI设计中,每个控件(Widget)都要手动地绑定在窗口之上的一个点上(也就是说,这个控件被指定成了给定GUI元素的父对象),同时还要指定这个控件的高度和宽度.作为所有图形元素的基础类,QW ...

  2. 怎样在 Swift 项目中使用 CocoaPods

    4个步骤,将 CocoaPods 导入 Swift 1.创建.编辑 Podfile 文件并 pod install 2.使用 File -> New -> File- 创建一个 Heade ...

  3. AIX-vi操作-提示Unknown terminal type的问题解决方法

    AIX-vi操作-提示Unknown terminal type的问题解决方法AIX Version 5.3$ vi /etc/profilelinux: Unknown terminal type[ ...

  4. 【指数型母函数+非递归快速幂】【HDU2065】"红色病毒"问题

    大一上学完数分上后终于可以搞懂指数型母函数了.. 需要一点关于泰勒级数的高数知识 题目在此: "红色病毒"问题 Time Limit: 1000/1000 MS (Java/Oth ...

  5. 类 的继承性(Inherits)与 重写(Overrides)

    (类) 与 (结构) 类似,让我们可以定义并封装成一组相关项的数据类型.比如封装成结构,那么这个封装包的数据类型就为值类型:如封装成类,那么这个封装包的数据类型就为引用类型. 然而与结构的一个重要区别 ...

  6. Windows下Vundle安装

    鼠标手老是发作,没办法.想学习vim尽量减少编码时使用鼠标的频率.安装好gVim开始安装Vundle插件,总结下安装过程和各种遇到的坑: github上VundleVim倒是有说明 Windows S ...

  7. PPT 制作必备工具

    1.图标 http://www.easyicon.net/ http://ico.58pic.com/ http://www.iconpng.com/ 2.字体 http://www.qiuziti. ...

  8. 从汇编看c++内联函数评估求值

    在c++中,一个inline函数实体,在整个class 声明未被完全看到之前,是不会被评估求值的,也就是说,对于类里面内联的成员函数本身的分析,要等到class的声明完全结束之后才开始.下面试c++源 ...

  9. word保存时标题变成黑框(mac版本)

    参考:http://blog.sina.com.cn/s/blog_686020310101i2zu.html 参考文档中说的时windows版本的word,跟我mac处理方式有一些不同: word版 ...

  10. html5 canvas 一个漫天飞雪的效果

    很棒的下雪效果 代码奉上 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...