被自己那“牛逼”的英語水平氣瘋了,在英語上WA了4次
對面那臺機子的王麻子說我的代碼又臭又長,還不會裝逼,沒有逼格,只會暴力。說博主是個野蠻人
沒辦法,水平不行,只能寫出來的東西當日記看咯
哎這裏介紹一篇不錯講優先隊列的博客,點這裏
思路:
若要找到只含有2,3,5,7的質因子,那麼將1丟到優先隊列中去分別枚舉相乘2,3,5,7,得到的結果再相去相乘2,3,5,7依次類推,最後打個表257ms
接下來的700ms跑,但是要注意的是去重,比如說2*3=6;六第一次丟到隊列中,然後枚舉3的時候3*2=6;就要去掉了
寫的其醜無比的代碼如下
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int num[4]={2,3,5,7};
struct cmp1
{
bool operator () (long long &a, long long &b)
{
return a > b ;
}
}; long long shu[10001];
int main()
{
int i;
priority_queue<long long,vector<long long>,cmp1 >q;
int o=0;
q.push(1);
long long b;
int pre=1;
while(o<=5880)
{
b=q.top();q.pop();
if(o!=0)
{
if(pre==b)
continue;
else
pre=b;
}
shu[o]=b;
o+=1;
for(i=0;i<4;i++)
{
q.push(num[i]*b);
}
}
int n;
while(cin>>n)
{
if(n==0)break;
int wei=n%10;
if(wei==1&&n%100!=11)
printf("The %dst",n);
else if(wei==2&&n%100!=12)
{
printf("The %dnd",n);
}
else if(wei==3&&n%100!=13)
{
printf("The %drd",n);
}
else
printf("The %dth",n);
printf(" humble number is %lld.\n", shu[n-1]);
}
return 0;
}