C++11新特性Move Semantic及实现的基础xvalue



知识点:

最小公倍数(a,b)=a*b/最大公约数(a,b)

Party

Description

The CEO of ACM (Association of Cryptographic Mavericks) organization has invited all of his teams to the annual all-hands meeting, being a very disciplined person, the CEO decided to give a money award
to the first team that shows up to the meeting.

The CEO knows the number of employees in each of his teams and wants to determine X the least amount of money he should bring so that he awards the first team to show up such that all team members receive the same amount of money. You must write a program to
help the CEO achieve this task.

Input

The input consists of multiple test cases, each test case is described on a line by itself, Each line starts with an integer N (1 <= N <= 20) the number of teams in the organization followed by N space
separated positive integers representing the number of employees in each of the N teams. You may assume that X will always fit in a 32 bit signed integer. The last line of input starts with 0 and shouldn‘t be processed.

Output

For each test case in the input print "The CEO must bring X pounds.", where X is as described above or "Too much money to pay!" if X is 1000000 or more.

Sample Input

1 3000000
2 12 4
0

Sample Output

Too much money to pay!
The CEO must bring 12 pounds.

#include<iostream>
#include<cstdio>

using namespace std;

__int64 num[30];

__int64 gcd(__int64 a,__int64 b)
{
    __int64 r;
    __int64 t;
    if(a<b)
    {
        t=a;
        a=b;
        b=t;
    }
    r=a%b;
    while(r)
    {
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

__int64 lcm(__int64 a,__int64 b)
{
    return a*b/gcd(a,b);        //如果是int ,a*b将会溢出,造成错误
}

int main()
{
   int t;
   __int64 res;
   while(scanf("%d",&t),t)
   {
       for(int i=0;i<t;i++)
        scanf("%I64d",num+i);
       res=num[0];
       //cout<<gcd(num[0],num[0]);

       for(int i=1;i<t;i++)
        res=lcm(num[i],res);

       if(res>=1000000)
           printf("Too much money to pay!\n");
        else
            printf("The CEO must bring %I64d pounds.\n",res);
   }
   return 0;
}

C++11新特性Move Semantic及实现的基础xvalue

时间: 2024-12-17 21:15:20

C++11新特性Move Semantic及实现的基础xvalue的相关文章

C++11新特性:右值引用和转移构造函数

问题背景 [cpp] view plaincopy #include <iostream> using namespace std; vector<int> doubleValues (const vector<int>& v) { vector<int> new_values( v.size() ); for (auto itr = new_values.begin(), end_itr = new_values.end(); itr != end

C++11 新特性(2) 移动语义

C++11支持移动语义. 一:为什么需要移动语义和什么是移动语义 我们先来看看C++11之前的复制过程.假设有下列代码: vector<string> v1(1000000);//v1存放着100W个string,假设每个string长度为1000 vector<string> v2(v1);//使用v1初始化v2 vector和string类都使用动态内存分配,因此他们必须定义使用他们自己的new版本的复制构造函数. 复制构造函数vector<string>将使用ne

9秒学院学C++11新特性

9秒学院C++11新特性学习笔记 分类: C/C++ 最近学习了C++11的新特性,将学习内容整理下来以巩固记忆,C++11的新特性,可以分为两部分,第一部分是C++11核心语言的特性,第二部分是STL标准库的新特性.学习C++11主要参考了wiki上的一篇文章,在介绍右值引用的时候还参考了MSDN上一篇文章,由于这两篇文章写的时间比较早,和实际有些出入,我的开发环境是win8,vs2012,很多C++11特性还没支持,所以只整理了vs2012已经支持了的特性. 第一部分:核心语言的特性 一.

C++11——新特性总结

前言: 开学过去一个半月了,说来十分惭愧,由于和女友最后还是分开了,导致这段时间一直在沉沦,每天晚上回去打打lol或者cs,就睡觉,基本上把我自己定下的自学目标给抛弃了.好在这段时间里还是凭借以前的基础投了不少岗位,也笔试了不少公司,基本都通过了笔试.第一次面试是网易,结果在最后一轮的技术面上挂了下来.其实回想起来,当时问的问题我其实之前都有仔细的专研过,只不过时间太久忘了罢了.这也要怪我自己准备不够充分.之前腾讯的笔试,我其实感觉自己是做砸了的,不过没想到还是得到了面试机会,就在两天之后的下午

逐个使用C++11新特性

C++11 auto & decltype auto:根据变量初始值来推导变量类型,并用右值初始化变量. decltype:从表达式推导出类型,并将变量定义为该类型,但不用表达式的值初始化该变量. 这里要注意下:decltype(i)--是i的类型,而decltype((i))就是引用了.就像上面例子中的x 就是int &x; 右值引用 新标准在拷贝构造函数.拷贝赋值运算符和析构函数之外,还增加了移动构造函数和移动赋值运算符,而这二位就需要右值引用的支持. 1. 延长将亡值的生命. 1 /

C++11 新特性之 tuple

我们在C++中都用过pair.pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同.pair可以使用make_pair构造 pair<int, string> p = make_pair(1, "a1"); 如果传入的参数为多个,那么就需要嵌套pair,如下代码 #include <iostream> #include <map> using namespace std; int main() { //<int, string,

C++11 新特性之 变长参数模板

template <typename ... ARGS> void fun(ARGS ... args) 首先明确几个概念 1,模板参数包(template parameter pack):它指模板参数位置上的变长参数,例如上面例子中的ARGS 2,函数参数包(function parameter pack):它指函数参数位置上的变长参数,例如上面例子中的args 一般情况下 参数包必须在最后面,例如: template <typename T, typename ... Args>

【C++11】30分钟了解C++11新特性

作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 什么是C++11 C++11是曾经被叫做C++0x,是对目前C++语言的扩展和修正,C++11不仅包含核心语言的新机能,而且扩展了C++的标准程序库(STL),并入了大部分的C++ Technical Report 1(TR1)程序库(数学的特殊函数除外). C++11包括大量的新特性:包括lambda表达式,类型推导关键字auto.decl

[C++11新特性]第二篇

0.可变数量参数,可变函数模版,变长模版类 c++98可变数量参数 #include<cstdio> #include<cstdarg> double SumOfFloat(int count, ...) { va_list ap; double sum=0; va_start(ap,count); for(int i=0;i<count;i++) sum+=va_arg(ap,double); va_end(ap); return sum; } int main() { p