额
格式有点、、、、
Problem A: 奇怪的排序
Time Limit: 1 Sec Memory Limit: 128 MBDescription
最近,Dr. Kong 新设计一个机器人Bill。这台机器人很聪明,会做许多事情。惟独对自然数的理解与人类不一样,它是从右往左读数。比如,它看到123时,会理解成321。让它比较23与15哪一个大,它说15大。原因是它的大脑会以为是32与51在进行比较。再比如让它比较29与30,它说29大。
给定Bill两个自然数A和B,让它将 [A,B] 区间中的所有数按从小到大排序出来。你会认为它如何排序?
Input
第一行: N 表示有多少组测试数据。
接下来有N行, 每一行有两个正整数A B 表示待排序元素的区间范围。
Output
对于每一行测试数据,输出一行,为所有排好序的元素,元素之间有一个空格。
Sample Input
2
8 15
22 39
Sample Output
10 8 9 11 12 13 14 15
30 31 22 32 23 33 24 34 25 35 26 36 27 37 28 38 29 39
HINT
2<=N<=5 1<=A<=B<=200000 B-A<=50。
简单的sort 就可以,先把数转化一下
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define N 55
int s[N];
struct node
{
int tr;
int fa;
}tt[N];
int get_num(int n)
{
memset(s, 0, sizeof(s));
int amt = 0;
int ans = 0;
while(n)
{
s[amt ++] = n % 10;
n /= 10;
}
for(int i = 0; i < amt ; i ++)
{
ans = ans * 10 + s[i];
}
return ans;
}
bool cmp(node a, node b)
{
if(a.fa < b.fa)
return true;
return false;
}
int main()
{
int t;
int n, m;
while(~scanf("%d",&t))
{
while(t --)
{
memset(tt, 0, sizeof(tt));
scanf("%d%d",&n,&m);
int cnt = 0;
for(int i = n; i <= m; i ++)
{
tt[cnt].tr = i;
tt[cnt ++].fa = get_num(i);
}
sort(tt, tt + m - n + 1, cmp);
printf("%d",tt[0].tr);
for(int i = 1; i < m - n + 1; i ++)
{
printf(" %d", tt[i].tr);
}
printf("\n");
}
}
}
/**************************************************************
User: Joursion
Language: C++
Result: Accepted
Time:0 ms
Memory:1316 kb
****************************************************************/
Problem B: 最强DE 战斗力
Time Limit: 1 Sec Memory Limit: 128 MBDescription
春秋战国时期,赵国地大物博,资源非常丰富,人民安居乐业。但许多国家对它虎视眈眈,准备联合起来对赵国发起一场战争。
显然,面对多个国家的部队去作战,赵国的兵力明显处于劣势。战斗力是决定战争成败的关键因素,一般来说,一支部队的战斗力与部队的兵力成正比。但当把一支部队分成若干个作战队伍时,这个部队的战斗力就会大大的增强。
一支部队的战斗力是可以通过以下两个规则计算出来的:
1.若一支作战队伍的兵力为N,则这支作战队伍的战斗力为N;
2.若将一支部队分为若干个作战队伍,则这支部队的总战斗力为这些作战队伍战斗力的乘积。
比如:一支部队的兵力为5时的战斗力分析如下:
情况 |
作战安排 |
总的战斗力 |
1 |
1,1,1,1,1(共分为5个作战队伍) |
1*1*1*1*1=1 |
2 |
1,1,1,2 (共分为4个作战队伍) |
1*1*1*2=2 |
3 |
1,2,2 (共分为3个作战队伍) |
1*2*2=4 |
4 |
1,1,3 (共分为3个作战队伍) |
1*1*3=3 |
5 |
2,3 (共分为2个作战队伍) |
2*3=6 |
6 |
1,4 (共分为2个作战队伍) |
1*4=4 |
7 |
5 (共分为1个作战队伍) |
5=5 |
显然,将部队分为2个作战队伍(一个为2,另一个为3),总的战斗力达到最大!
Input
第一行: N 表示有N组测试数据。 (2<=N<=5)
接下来有N行,每行有一个整数Ti 代表赵国部队的兵力。 (1 <= Ti <= 1000)i=1,…N
Output
对于每一行测试数据,输出占一行,仅一个整数S, 表示作战安排的最大战斗力。
Sample Input
2
5
4
Sample Output
6
4
另外需要注意的事,最大的数是3^332 * 4 ,我还天真地用了double、、、直接上大数吧!
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
#define N 1010
int ans[N];
void big_num(int t)
{
int tmp_1 = 0;
int tmp_2;
for(int i = 0; i < 999; i ++)
{
tmp_2 = ans[i]*t + tmp_1;
ans[i] = tmp_2 % 10;
tmp_1 = tmp_2 / 10;
}
}
int main()
{
int t, n;
while(~scanf("%d",&t))
{
while(t --)
{
memset(ans, 0, sizeof(ans));
int cnt = 0;
int tt = 1;
scanf("%d",&n);
if(n <= 4)
{
printf("%d\n",n);
continue;
}
if(n % 3 == 0)
{
cnt = n/ 3;
}
else if(n % 3 == 1)
{
cnt = n / 3 - 1;
tt = 4;
}
else
{
cnt = n / 3;
tt = 2;
}
ans[0] = 1;
for(int i = 0; i < cnt; i ++)
{
big_num(3);
}
big_num(tt);
bool tag = false;
for(int i = 999; i >= 0; i --)
{
if(tag)
{
printf("%d",ans[i]);
continue;
}
if(ans[i])
{
tag = true;
printf("%d",ans[i]);
}
}
printf("\n");
}
}
}
/**************************************************************
User: Joursion
Language: C++
Result: Accepted
Time:4 ms
Memory:1316 kb
****************************************************************/