锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Description Input Output Sample Input Sample Output Source Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesting properties.
In order to test the algorithm's efficiency, she collects many datasets. What's more, each data is divided into two parts: training data and test data. She gets the parameters of the model on training data and test the model on test data.
To her surprise, she finds each dataset's test error curve is just a parabolic curve. A parabolic curve corresponds to a quadratic function. In mathematics, a quadratic function is a polynomial function of the form f(x) = ax2 + bx + c. The quadratic will degrade to linear function if a = 0.
It's very easy to calculate the minimal error if there is only one test error curve. However, there are several datasets, which means Josephina will obtain many parabolic curves. Josephina wants to get the tuned parameters that make the best performance on all datasets. So she should take all error curves into account, i.e., she has to deal with many quadric functions and make a new error definition to represent the total error. Now, she focuses on the following new function's minimal which related to multiple quadric functions.
The new function F(x) is defined as follow:
F(x) = max(Si(x)), i = 1...n. The domain of x is [0, 1000]. Si(x) is a quadric function. Josephina wonders the minimum of F(x). Unfortunately, it's too hard for her to solve this problem. As a super programmer, can you help her?
The input contains multiple test cases. The first line is the number of cases T (T < 100). Each case begins with a number n(n ≤ 10000). Following n lines, each line contains three integers a (0 ≤ a ≤ 100), b (|b| ≤ 5000), c (|c| ≤ 5000), which mean the corresponding coefficients of a quadratic function. For each test case, output the answer in a line. Round to 4 digits after the decimal point. Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1832 Accepted: 737
Soon a second man woke up and did the same thing. After dividing the coconuts into five piles, one coconut was left over which he gave to the monkey. He then hid his share and went back to bed. The third, fourth, and fifth man followed exactly the same procedure. The next morning, after they all woke up, they divided the remaining coconuts into five equal shares. This time no coconuts were left over.
An obvious question is "how many coconuts did they originally gather?" There are an infinite number of answers, but the lowest of these is 3,121. But that's not our problem here.
Suppose we turn the problem around. If we know the number of coconuts that were gathered, what is the maximum number of persons (and one monkey) that could have been shipwrecked if the same procedure could occur? 25 30 3121 -1
25 coconuts, 3 people and 1 monkey 30 coconuts, no solution 3121 coconuts, 5 people and 1 monkey
瑙f硶錛?br />棣栧厛鍐欏嚭閫掓帹鍏紡
f(0)=A A=nk
f(i)=f(i-1)/(n-1)*n+1
闅忎究浠涔堟柟娉曞啓鍑洪棴褰㈠紡
f(n)=[錛坣^n錛?錛圓+n-1錛塢/[錛坣-1錛塣n]-(n-1)
棰樼洰涓憡璇塮(n)鐨勫鹼紝姹俷鏈澶у?br />棣栧厛瑙傚療涓嬪墠闈㈤偅涓垎寮忥紝鐢變簬n鍜宯-1浜掕川錛屾墍浠^n鍜?n-1)^n涔熶簰璐?/span>錛屽垎寮忕粨鏋滆涓轟竴涓暣鏁幫紝f(n)+n-1涓繀欏誨惈鏈夊洜瀛恘^n錛涙崲鍙ヨ瘽璇達紝f(n)+n-1>n^n,棰樼洰涓粰鐨刦(n)鍙互鐢?2浣嶆暣鏁拌〃紺猴紝閭d箞n蹇呯劧灝忎簬12錛?/span>
涓嬮潰涓嶇敤璇翠粈涔堜簡錛屾毚鍔涘惂錛岃偗瀹?MS浜唦涓嶈繃涓轟簡瀹岀編錛宯^n鎴戠敤浜嗕簩榪涘埗蹇熷箓~鍏蜂綋鐪嬩唬鐮佸惂
浠g爜錛?br />
2 Problem: 1309 User: yzhw
3 Memory: 392K Time: 0MS
4 Language: G++ Result: Accepted
5
6 Source Code
7
8 # include <cstdio>
9 using namespace std;
10 long long pow(int a,int b)
11 {
12 long long ans=1,t=a;
13 while(b)
14 {
15 if(b&1) ans*=t;
16 t*=t;
17 b>>=1;
18 }
19 return ans;
20 }
21 int main()
22 {
23 //freopen("input.txt","r",stdin);
24 int n;
25 while(scanf("%d",&n)!=EOF&&n>=0)
26 {
27 int ans=-1,i;
28 for(i=2;i<=12;i++)
29 {
30 long long t=n;
31 t+=i-1;
32 long long t1=pow(i,i),t2=pow(i-1,i);
33 if(t%t1==0)
34 {
35 t=t/t1*t2-i+1;
36 if(t>=0&&t%i==0) ans=i;
37 }
38 }
39 if(ans==-1) printf("%d coconuts, no solution\n",n);
40 else printf("%d coconuts, %d people and 1 monkey\n",n,ans);
41 }
42 return 0;
43 }
44
45
]]>
]]>
]]>
灝哄錛氶泦瑁呯 8*40 ,姘村鉤闂磋窛錛?錛岀珫鐩撮棿璺濓細2
棰樿В錛?br>鏋氫婦綰靛悜涓暟錛屾灇涓懼埌sqrt(涓婂彇鏁達紙n/5)鍗沖彲銆?br>
紼嬪簭錛?br>
import java.util.*;
2
public class Main
{
3
4
/** *//**
5
* @param args
6
*/
7
public static void main(String[] args)
{
8
Scanner in=new Scanner(System.in);
9
int test=in.nextInt();
10
while((test--)!=0)
11
{
12
long num=in.nextLong();
13
num=(num%5==0?num/5:num/5+1);
14
long r1=Long.MAX_VALUE,r2=Long.MAX_VALUE,l=0,w = 0;
15
for(long a=1;a*a<=num;a++)
16
{
17
long b=(num%a==0?num/a:num/a+1);
18
if((a*44+4)*(b*10+2)<r1||(a*44+4)*(b*10+2)==r1&&Math.abs((a*44+4)-(b*10+2))<r2)
19
{
20
r1=(a*44+4)*(b*10+2);
21
r2=Math.abs((a*44+4)-(b*10+2));
22
l=(a*44+4);
23
w=(b*10+2);
24
}
25
if(b==1) break;
26
}
27
System.out.println(Math.max(w,l)+" X "+Math.min(w, l)+" = "+r1);
28
}
29
30
}
31
32
}
33
]]>

Input
Output
Sample Input
2
1
2 0 0
2
2 0 0
2 -4 2
Sample Output
0.0000
0.5000
綆鏄庨鎰忥細姹備竴鍫?span style="COLOR: red">寮鍙e悜涓?/span>鐨勪簩嬈″嚱鏁板湪[0,1000]鑼冨洿涓婂嚱鏁板兼渶澶у肩殑鏈灝忓箋?/pre>
浜屾鍑芥暟鐨勫瓙闆嗕粛鐒朵負鍑稿嚱鏁幫紝鎵浠ュ彲浠ョ敤涓夊垎娉曟眰鏋佸箋傜簿搴﹀疄鍦ㄥ緢铔嬬柤錛岃繖棰樿姹傚煎煙綺劇‘鍒?e-4錛屼絾鏄畾涔夊煙娌¤綺劇‘鍒板灝戯紝緇撴灉姝粀a錛屽崱鍒?e-10緇堜簬榪囦簡銆傘?/pre>
璐翠唬鐮?/pre>
# include <cstdio>
2
# include <cmath>
3
using namespace std;
4
int n;
5
int data[10001][3];
6
# define max(a,b) ((a)>(b)?(a):(b))
7
double cal(double mid)
8

{
9
double res=-1e26;
10
for(int i=0;i<n;i++)
11
res=max(res,data[i][0]*mid*mid+data[i][1]*mid+data[i][2]);
12
return res;
13
}
14
int main()
15

{
16
int test;
17
scanf("%d",&test);
18
while(test--)
19
{
20
scanf("%d",&n);
21
for(int i=0;i<n;i++)
22
scanf("%d%d%d",&data[i][0],&data[i][1],&data[i][2]);
23
double s=0.0,e=1000.0;
24
double last=s;
25
while(fabs(e-s)>1e-10)
26
{
27
28
double m1=(s+e)/2.0,m2=(m1+e)/2.0;
29
if(cal(m1)<cal(m2))
30
e=m2;
31
else
32
s=m1;
33
}
34
printf("%.4lf\n",cal(e));
35
}
36
return 0;
37
}
38
39
]]>
2 import java.util.Arrays;
3 public class Main {
4
5 /**
6 * @param args
7 */
8 static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
9 //static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))));
10 static final int readInt() throws Exception
11 {
12 in.nextToken();
13 return (int)in.nval;
14 }
15 static class node implements Comparable<node>
16 {
17 int t,x,s,e;
18 public int compareTo(node pos)
19 {
20 if(e!=pos.e) return e-pos.e;
21 else return s-pos.s;
22 }
23 }
24 static node data[]=new node[100005];
25 public static void main(String[] args) throws Exception{
26 int n=readInt();
27 for(int i=0;i<100005;i++)
28 data[i]=new node();
29 for(int test=1;test<=n;test++)
30 {
31 int num=readInt(),limit=readInt(),e=4000000,s=-4000000;
32 for(int i=0;i<num;i++)
33 {
34 data[i].t=readInt();
35 data[i].x=readInt();
36 e=Math.min(e, data[i].t);
37 }
38 while(s<=e)
39 {
40 int mid=(s+e)>>1,count=1;
41 for(int i=0;i<num;i++)
42 {
43 data[i].s=data[i].x-data[i].t+mid;
44 data[i].e=data[i].x+data[i].t-mid;
45 }
46
47 Arrays.sort(data,0,num);
48 int laste=data[0].e;
49 for(int i=1;i<num;i++)
50 if(data[i].s<=laste)
51 continue;
52 else
53 {
54 count++;
55 laste=data[i].e;
56 }
57 if(count<=limit)
58 s=mid+1;
59 else
60 e=mid-1;
61 }
62 System.out.println("Case "+test+": "+e);
63 }
64
65 }
66
67 }
68
]]>
]]>
/**//*
2
Source Code
3
4
Problem: 1855 User: yzhw
5
Memory: 8648K Time: 313MS
6
Language: G++ Result: Accepted
7
*/
8
9
10
# include <iostream>
11
# include <cstdio>
12
using namespace std;
13
int l[51];
14
int refer[51][51][51][51];
15
int gcd(int a,int b)
16

{
17
while(b)
18
{
19
int t=a%b;
20
a=b;
21
b=t;
22
}
23
return a;
24
}
25
int main()
26

{
27
int n,t;
28
while(true)
29
{
30
scanf("%d%d",&n,&t);
31
if(!n&&!t) break;
32
for(int i=0;i<n;i++)
33
scanf("%d",l+i);
34
for(int a=0;a<n;a++)
35
for(int b=a+1;b<n;b++)
36
//if(a!=b)
37
for(int c=b+1;c<n;c++)
38
//if(a!=c&&b!=c)
39
for(int d=c+1;d<n;d++)
40
//if(a!=d&&b!=d&&c!=d)
41
{
42
int lcd1=l[a]*l[b]/gcd(l[a],l[b]),lcd2=l[c]*l[d]/gcd(l[c],l[d]);
43
int lcd=lcd1*lcd2/gcd(lcd1,lcd2);
44
refer[a][b][c][d]=lcd;
45
46
}
47
48
while(t--)
49
{
50
int minnum=0xfffffff,maxnum=-1;
51
int pos;
52
scanf("%d",&pos);
53
for(int a=0;a<n;a++)
54
for(int b=a+1;b<n;b++)
55
for(int c=b+1;c<n;c++)
56
for(int d=c+1;d<n;d++)
57
{
58
59
int lcd=refer[a][b][c][d];
60
if(pos-pos%lcd>maxnum)
61
maxnum=pos-pos%lcd;
62
if(pos%lcd&&lcd*(pos/lcd+1)<minnum)
63
minnum=lcd*(pos/lcd+1);
64
if(pos%lcd==0&&pos<minnum)
65
minnum=pos;
66
67
}
68
printf("%d %d\n",maxnum,minnum);
69
}
70
}
71
return 0;
72
}
73
74
]]>