Question A: sciorz painting
Title Description
As we all know, sciorz will paint. Day, sciorz drew a convex polygon, the vertex of each polygon has a weight value a [i]. sciorz think this convex polygon not beautiful, he decided between the n connection points, end-n 3-strip lines do not intersect this convex polygon is divided into n n-2 triangles. sciorz considered a beautiful triangle vertex values are the product of three weights, the value of beauty convex polygon inside the triangle is its beauty and value. sciorz trying to find a partitioning scheme, so that the beauty of this convex polygon the maximum. sciorz busy brush problem, so he readily took the title throw you sign, I hope you help sciorz calculate the maximum value of beauty.
Entry
A first line t, t expressed set of sample.
The first sample of each group is a row n, the number of sides of the polygon.
Second line number n, denotes the i-th weight of the i-th vertex of the polygon values a [i], given in counterclockwise order.
The first sample of each group is a row n, the number of sides of the polygon.
Second line number n, denotes the i-th weight of the i-th vertex of the polygon values a [i], given in counterclockwise order.
Export
For each sample, the output line. Format "Case #x: y", x is the sample number, y is the answer.
Sample input Copy
2
3
1 2 3
4
1 2 3 4
Sample output Copy
Case #1: 6
Case #2: 32
prompt
The first sample is only a triangle, so do not split, the answer is 1 * 2 * 3 = 6.
Second triangle, the optimal partitioning scheme is divided into 124 and 234 two triangles, the answer is. 4 * 2 + *. 1 * 2 *. 3. 4 = 32
. 1 <= T <= 100
. 3 <= n-< 100 =
. 1 <= A [I] <= 100
Second triangle, the optimal partitioning scheme is divided into 124 and 234 two triangles, the answer is. 4 * 2 + *. 1 * 2 *. 3. 4 = 32
. 1 <= T <= 100
. 3 <= n-< 100 =
. 1 <= A [I] <= 100
Beginning to forget output format, the two inexplicable wa hair, hand cut
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define ll long long using namespace std; int n; ll a[1000]; ll dp[1000][1000]; int ca=1; void solve() { memset(a,0,sizeof 0); memset(dp,0,sizeof(dp)); scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%lld",&a[i]); for(int i=n; i>=1; i--) { for(int j=i+1; j<=n; j++) { if(j-i==1) dp[i][j]=0; else if(j-i==2) dp[i][j]=a[i]*a[i+1]*a[i+2]; else for(int k=i+1; k<=j-1; k++) { dp[i][j]=max(dp[i][j],(dp[i][k]+dp[k][j]+a[i]*a[j]*a[k])); } } } printf("Case #%d: ",ca++); printf("%lld\n",dp[1][n]); } int main() { int t; cin>>t; while(t--) solve(); return 0; }
Problem B: Kuikui red envelopes
Title Description
Valentine's Day came around again, went to the annual red envelopes of time. After it decided this year to let Kuikui voluntary red envelopes.
Club n individuals (0 <n <100000), each person has a single value of v [i] and intimacy t [i] (0≤v [i ] ≤10000,0≤t [i] ≤10000), the larger the value of a single person, the more envy Kuikui in time for Valentine's Day, Kuikui need to give him more of a red envelope to comfort him. Due to a winter did not see Kuikui, red collar when everyone wants to Kuikui py, spend time t [i], py to after the first red envelope Oh.
We are tired of waiting, if a person such as the time t, then Kuikui sent him a red envelope size is v [i] · t.
But also Kuikui and his girlfriend happy, I want to spend the least money to satisfy everyone.
Please help you calculate how much money he had at least need to send red envelopes.
Club n individuals (0 <n <100000), each person has a single value of v [i] and intimacy t [i] (0≤v [i ] ≤10000,0≤t [i] ≤10000), the larger the value of a single person, the more envy Kuikui in time for Valentine's Day, Kuikui need to give him more of a red envelope to comfort him. Due to a winter did not see Kuikui, red collar when everyone wants to Kuikui py, spend time t [i], py to after the first red envelope Oh.
We are tired of waiting, if a person such as the time t, then Kuikui sent him a red envelope size is v [i] · t.
But also Kuikui and his girlfriend happy, I want to spend the least money to satisfy everyone.
Please help you calculate how much money he had at least need to send red envelopes.
Entry
A first line integer n. Next n lines of two numbers v [i] and t [i].
Export
An integer that represents the answer.
Sample input Copy
4
1 4
2 3
3 2
4 1
Sample output Copy
35
#include<iostream> #include<algorithm> #include<cstring> using namespace std ; const int N=100010; typedef long long ll; int f[N]; struct S { int v,t; } st[N]; bool cmp(S a,S b) { return a.t*b.v<a.v*b.t; } int main() { int t=1; for(int c=1; c<=t; c++) { int n; cin>>n; for(int i=0; i<n; i++) { int s,e; cin>>s>>e; st[i]= {s,e}; } sort(st,st+n,cmp); ll ans=0; ll sum=0; for(int i=0; i<n; i++) { ans+=st[i].t; sum+=st[i].v*ans; } cout<<sum<<endl; } }
Problem C: About my reincarnation become slime thing this file
Title Description
About my reincarnation become slime that it exists this thing play Fan, Wu on the three office workers because of an event as the reincarnation of slime in a different world. We got "great sage" and "Predator" These two unique skills in the reincarnation. Although as a slime, but also want to establish friendly relations with other races. Quintessence is a different world inside the magic essence Monster contained predators devour this skill is magic elements, predators skill is very demanding, if you swallowed the first day b Quintessence, then you can swallow the next day the first day 2 to 9 times (one of which must be an integer), i.e. 2b ~ 9b, that is to say, in the slime swallowed Quintessence day i must be 2 to 9 times the first day i-1, but also it must be an integer multiple.
As the right-hand man slime men, goblins have prepared a lot for the owner of Monster consumption, now Slime Monster already know these contain S Quintessence, now give the great sage arrange the first day and then to devour down the need to increase the daily Quintessence multiples, so slime can swallow just finished Quintessence in the shortest number of days. As the great sage to study "philosophy" to attend to these little things, I can only ask you to help, but the great sage also suggested that these magic hormone use at least two days swallowed.
As the right-hand man slime men, goblins have prepared a lot for the owner of Monster consumption, now Slime Monster already know these contain S Quintessence, now give the great sage arrange the first day and then to devour down the need to increase the daily Quintessence multiples, so slime can swallow just finished Quintessence in the shortest number of days. As the great sage to study "philosophy" to attend to these little things, I can only ask you to help, but the great sage also suggested that these magic hormone use at least two days swallowed.
Entry
Su total magic a positive integer S, to be the representative swallowed.
Export
A number representative of the number of days to be swallowed, if no solution outputs -1.
Sample input Copy
571
Sample output Copy
5
prompt
For 30% of the data, there are S <= 100;
for 70% of the data, there are S <= 107;
to 100% of the data, there are 9 <S <= 8 × 108
for 70% of the data, there are S <= 107;
to 100% of the data, there are 9 <S <= 8 × 108
metaphysics
#include <the iostream> the using namespace STD; typedef Long Long LL; const int INF = 0x3f3f3f3f ; int Read () { int RES = 0 , CH, In Flag = 0 ; IF ((CH = getchar ()) == ' - ' ) // Analyzing negative in Flag = . 1 ; the else IF (CH> = ' 0 ' && CH <= ' . 9 ' ) // get complete number res = ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } ll ans=INF; ll calc(ll n) { if(n<2)return INF; if(2<=n&&n<=9)return 1; ll res=INF; for(ll i=2;i<=9;++i) if(n%i==0) res=min(res,calc(n/i-1)+1); return res; } int main() { ll n=read(); for(ll i=1;i*i<=n;++i) if(n%i==0) { ans=min(ans,calc(n/i-1)+1); if(i!=1) ans=min(ans,calc(i-1)+1); } if(ans==INF)puts("-1"); else std::cout<<ans; return 0; }
Question D: Tarsus
Title Description
Seven is a very cute little very hard girl. She operations on large numbers of very interested in learning after a few days, and finally mastered addition and subtraction, multiplication and division of large numbers. But since she learned JAVA, she felt that large numbers is too simple and too boring, because the use of JAVA in BigInteger large integer class, you can easily add and subtract, multiply and divide large numbers. One day she suddenly found that many of the problems of large numbers of data are laws. These numbers are repeated consists of a number smaller than he, for example, consists of 12 duplicate 121212, 233233, by the repetition of 233, 123 and 1,231,231 is not composed of repeating. Silly little seven finally found a fun, she wants to find large numbers each of which is smaller than the number of repeating its constitution. Algorithms small seven newly recruited ⻔ not solve the problem, so she turned to you.
Entry
Line a positive integer n (n <= 101000000).
Export
Line
if more, the minimum number of output intended to meet the problem of the presence;
if not, outputs -1.
if more, the minimum number of output intended to meet the problem of the presence;
if not, outputs -1.
Sample input Copy
121212
Sample output Copy
12
#include <bits/stdc++.h> #define rep(i, l, r) for (int i = l; i <= r; ++ i) using namespace std; const int MaxN = 1e7 + 10; int n; char s1[MaxN]; int p[MaxN]; int main() { scanf("%s", s1 + 1); n = strlen(s1 + 1); if (n == 0) return 0; int j = 0; rep (i, 1, (n - 1)) { while (j > 0 && s1[j + 1] != s1[i + 1]) j = p[j]; if (s1[j + 1] == s1[i + 1]) j ++; p[i + 1] = j; } if (n % (n - p[n]) != 0 || n == (n - p[n])) printf("-1"); else rep (i, 1, n - p[n]) cout << s1[i]; return 0; }
Question E: Ktree
Title Description
Alchemist Yeongam at a disadvantage in the process with a wizard Slanely compete in the pie, so Yeongam call out to compete with the K tree pie. K is a tree of weights and s but undetermined weight distribution tree. Slanely secretly cast spells, the K tree diameter as small as possible. Now summon Yeongam I want to know how much K-diameter trees.
Entry
The first line gives two integers n and s, n, s <= 100000 , n is the number of nodes, s is the total length of the tree.
Next, in each row two integers u, v, expressed coupled to an edge between the nodes u and v.
Next, in each row two integers u, v, expressed coupled to an edge between the nodes u and v.
Export
Output L, with two decimal places.
Sample input Copy
6 4
1 2
1 3
1 4
4 5
4 6
Sample output Copy
2.00