CodeForces 515C

Cat
Time Limit: 1500MS Memory Limit: 30000K
Total Submissions: 1580 Accepted: 401 Special Judge

Description

In strong winds, sailboats tend to heel leeward (tilt away from the wind) like the one in the picture. Heeling is undesirable for at least two reasons. First, the effective sail area is reduced, as the effective height of the sail is multiplied by the cosine of the angle. Reduced sail area implies reduced speed. Second, the boat may heel to the point that its centre of gravity ceases to be above the hull, causing the boat to capsize.
To mitigate these problems, catamarans like the one shown split the hull into two pieces (the port and starboard hulls). This design increases the effective width of the boat. Increased width decreases the vertical mechanical advantage of the sail, thus reducing heeling. Increased width also increases the angle of heeling that can be tolerated before the boat capsizes.

Heeling can also be mitigated by having the crew sit or stand on, or even hike out beyond, the windward hull. If you look carefully at the picture you can see the two person crew hiking to windward.

At some wind velocity, even these measures are insufficient to keep the boat upright. A skipper's only choice (other than to capsize) is to let out the sail, which reduces its effective horizontal dimension much as heeling reduces its vertical dimension. As with heeling, this action causes loss of speed. If the boat heels sufficiently, it may not even be possible to let out the sail, as its outer corner may be obstructed by the surface of the water!

Reefing is a mechanism for reducing the sail's area. Roller reefing involves wrapping the sail around the boom (much like a window blind) so as to reduce its height. With sufficient reefing, the heeling can be controlled in almost any wind.

But reefing involves reduced speed, so our skipper has elected yet another approach. She has decided to beach the boat and pick up some rocks to use as ballast. Ballast is just dead weight added to hull, which tends to counteract heeling. It slows the boat a bit (as it rides lower in the water) but not nearly so much as reducing sail area.

Given n rocks, you are to compute how to divide them between the port and starboard hulls so that the weight of rocks in each hull is nearly equal.

Input

Input contains several test cases. Each test case begins with 1 < n <= 100; the number of rocks to be added as ballast. Consider the rocks to be numbered 1 through n. n lines follow; the ith line gives the weight in kg of the ith rock - a positive real number not greater than 100. A line containing 0 follows the last test case.

Output

For each test case, output a single line giving the numbers of the rocks that should be loaded as ballast into the starboard hull. Assume that the other rocks will be loaded into the port hull. The total weight of ballast in the port hull should not differ from that in the starboard hull by more than 2%. If there are many solutions, any one will do. There will always be a solution; indeed, there will always be a solution that balances within 1%, but you aren't required to find it.

Sample Input

5
10.0
50.0
90.0
38.0
7.1
0

Sample Output

3 5

Source

 

题意:给你一个数,然后给定一个运算规则f(x)=x中各个位上数字的阶乘之积为t,然后求出一个数使得这个数是经过运算规则f后所得值与t相等的最大数;

解题思路:

1.把每一个数的阶乘都展开,例如:F(135)=1!*3!*5!=1*3*2*1*5*4*3*2*1;可以看出在上述的例子当中54各出现了一次,32各出现了两次,我们把展开后每一个数字的出现次数用一个数组num存下来。

2.对于合数把它分解开,例如:9分解为3*3,8分解为2*2*2,6分解为2*3,4分解为2*2,也就是说把num中的合数都分解成质数(为什么要分解呢?因为要保证所得的数尽量大,所以要把大的数都分解开来,尽量分解成23,保证了最后得到的结果的数最长,自然就最大)。

3.7开始统计,num[1]num[6]都要减去num[7],因为是7!,在这里要注意的一个问题是此时的num[6],num[4]都为0,所以这是64又要从23生成出来。然后统计num[5]...num[3],num[2]...

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 using namespace std;
 7 int num[10],ans[10];
 8 int n;
 9 int main()
10 {
11     //freopen("in.txt","r",stdin);
12     while(~scanf("%d",&n)){
13         memset(num,0,sizeof(num));
14         memset(ans,0,sizeof(ans));
15         char str[20];
16         scanf("%s",str);
17         int l=strlen(str);
18         for(int i=0;i<l;i++)
19         {
20             for(int j=1;j<=str[i]-'0';j++)
21                 num[j]++;
22         }
23         for(int i=9;i>=2;i--)
24         {
25             if(i==9) num[3]+=2*num[9],num[9]=0;
26             else if(i==8) num[2]+=3*num[8],num[8]=0;
27             else if(i==6) num[2]+=num[6],num[3]+=num[6],num[6]=0;
28             else if(i==4) num[2]+=2*num[4],num[4]=0;
29         }
30         for(int i=7;i>=2;i--)
31         {
32             if(i==7){
33                 if(num[7]>0){
34                     num[2]-=4*num[7];
35                     num[3]-=2*num[7];
36                     num[5]-=num[7];
37                     ans[7]=num[7];
38                 }}
39                 else if(i==5){
40                     if(num[5]>0){
41                         num[2]-=3*num[5];
42                         num[3]-=num[5];
43                         ans[5]=num[5];
44                     }
45                 }
46                 else if(i==3){
47                     if(num[3]>0){
48                         num[2]-=num[3];
49                         ans[3]=num[3];
50                     }
51                 }
52             ans[2]=num[2];
53         }
54         for(int i=7;i>=2;i--){
55             for(int j=1;j<=num[i];j++)
56             {
57                 printf("%d",i);
58             }
59         }
60         printf("\n");
61     }
62     return 0;
63 }

 

 

 

转载于:https://www.cnblogs.com/codeyuan/p/4328426.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值