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

Waterloo local 2004.09.19

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

解题思路:

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

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

3.从7开始统计,num[1]到num[6]都要减去num[7],因为是7!,在这里要注意的一个问题是此时的num[6],num[4]都为0,所以这是6和4又要从2和3生成出来。然后统计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 }
时间: 2024-10-09 21:02:11

CodeForces 515C的相关文章

Codeforces 515C. Drazil and Factorial

//codeforces 515C. Drazil and Factorial #include <iostream> #include <cstring> #include <cstdio> using namespace std; /** 4!=2!*2!*3! 6!=1*2*3*4*5*6=5!*3! 8!=1*2*3*4*5*6*7*8=7!*2!*2!*2! 9!=1*2*3*4*5*6*7*8*9=7!*2!*3!*3! */ int main() { ch

codeforces 515C. Drazil and Factorial 解题报告

题目链接:http://codeforces.com/problemset/problem/515/C 题目意思:给出含有 n 个只有阿拉伯数字的字符串a(可能会有前导0),设定函数F(a) = 每个数字的阶乘乘积.例如 F(135) = 1! * 3! * 5! .需要找出 x,使得F(x) = F(a),且组成 x 的数字中没有0和1.求最大的 x 为多少. 这个我是看了每个数字的转换才知道怎么做的. 0, 1     —— >  empty(用空串表示) 2         —— > 

Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C

C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Drazil is playing a math game with Varda. Let's define  for positive integer x as a product of factorials of its dig

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp