现在的位置: 首页 > 综合 > 正文

暑假经历之ACM培训第七天--做一个简单题目安慰一下

2013年10月26日 ⁄ 综合 ⁄ 共 909字 ⁄ 字号 评论关闭

             我的AC率还处于低迷状态。第六天结束时匆匆写完blgo就回去了,是我们这边实验室最后走的。看看时间,11:40。还好没有到第七天。回去吹水了一下,大家就睡着了。终于有累的感觉。今天早上一到实验室,跳闸了,不过我这边的机子没事,可惜不能上网,于是找了两道比较简单的题目做了一下。一个是ugly number,一个移动盒子题。不过第二题由于理解命令错误了,后来就懒得改了。

/*
Ugly numbers are numbers whose only prime factors are 2, 3 or 5.
The sequence   1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...
shows the first 11 ugly numbers. By convention, 1 is included.
Write a program to find and print the 1500'th ugly number.
*/

#include "stdio.h"
#include "vector"
#include "algorithm"
using namespace std;

int main()
{
 vector<int> q;
 int count=0,i=0,n,j[3];
 q.push_back(1);
 while(count<=1500){
  for(i=0;i<q.size();i++){
   j[0]=q.at(i)*2;
   if(j[0]>q.back())
    break;
  }
  for(i=0;i<q.size();i++){
   j[1]=q.at(i)*3;
   if(j[1]>q.back())
    break;
  }
  for(i=0;i<q.size();i++){
   j[2]=q.at(i)*5;
   if(j[2]>q.back())
    break;
  }
  sort(j,j+3);
  q.push_back(j[0]);
  count++;
 }
 sort(q.begin(),q.end());
 while(scanf("%d",&i)&&i)
  printf("%d/n",q.at(i-1));
 return 0;
}

抱歉!评论已关闭.