锘??xml version="1.0" encoding="utf-8" standalone="yes"?> A narrow street is lined with tall buildings. An x foot long ladder is rested at the base of the building on the right side of the street and leans on the building on the left side. A y foot long ladder is rested at the base of the building on the left side of the street and leans on the building on the right side. The point where the two ladders cross is exactly c feet from the ground. How wide is the street? Each line of input contains three positive floating point numbers giving the values of x, y, and c. For each line of input, output one line with a floating point number giving the width of the street in feet, with three decimal digits in the fraction.
Input Specification
Output Specification
Sample Input
30 40 10
12.619429 8.163332 3
10 10 3
10 10 1
Sample Output
26.033
7.000
8.000
9.798
joj嫻嬭瘯鏁版嵁寰堝急錛屽彲鑳藉湪鍏朵粬oj涓婅繃涓嶄簡(jiǎn)錛屾牴鎹笁瑙掑艦鐩鎬技寰楀嚭浠ヤ笅鍏充簬w鐨勬柟紼嬶紝瑙錛岀涓嬈$敤浜屽垎娉曪紝涓嶉敊銆?br>f(w) = c - sqrt((y*y-w*w)*(x*x-w*w))/(sqrt(y*y-w*w) + sqrt(x*x -w*w))
#include<cstdlib>
#include<iomanip>
#include<math.h>
using namespace std;
//f(w) = c - sqrt((y*y-w*w)*(x*x-w*w))/(sqrt(y*y-w*w) + sqrt(x*x -w*w))
double func(double x,double y,double c)
{
double wdown=0.0,wup,w,fw;
if(x>y)
wup=y;
else
wup=x;
w=wup/2.0;
while(1)
{
fw=c-sqrt((y*y-w*w)*(x*x-w*w))/(sqrt(y*y-w*w) + sqrt(x*x -w*w));
if(fw>0.0001)
{
wup=w;
w=(wup+wdown)/2;
}
else
{
if(fw<-0.0001)
{
wdown=w;
w=(wup+wdown)/2;
}
else
{
return w;
}
}
}
}
int main()
{ //freopen("s.txt","r",stdin);
//freopen("key.txt","w",stdout);
double x,y,c;
while( cin>>x>>y>>c)
{
cout<<fixed<<setprecision(3)<<func(x,y,c)<<endl;
}
//system("PAUSE");
return 0;
}
]]>
Status | In/Out | TIME Limit | MEMORY Limit | Submit Times | Solved Users | JUDGE TYPE |
---|---|---|---|---|---|---|
![]() |
stdin/stdout | 3s | 10240K | 717 | 196 | Standard |
Mr. Jojer is a very famous chemist. He is doing a research about behavior of a group of atoms. Atoms may have different energy and energy can be positive or negative or zero, e.g. 18 or -9. Absolute value of energy can not be more than 100. Any number of continuous atoms can form an atom-group. Energy of an atom-group is defined by the sum of energy of all the atoms in the group. All the atoms form an atom-community which is a line formed by all the atoms one by one. Energy of an atom-community is defined by the greatest energy of an atom-group that can be formed by atoms in the atom-community. The problem is, given an atom-community, to calculate its energy.
The input contains several test cases. Each test case consists of two lines describing an atom-community. The first line of each test case contains an integer N(N<=1000000), the number of atoms in the atom-community. The second line of each test case contains N integers, separated by spaces, each representing energy of an atom, given in the order according to the atom-community. The last test case marks by N=-1, which you should not proceed.
For each test case(atom-community description), print a single line containing the energy.
5 8 0 6 4 -1 -1
18
鐞嗚В棰樻剰寰堥噸瑕侊紝棰樼洰鐨勬剰鎬濇槸璇?鍦╩涓腑閫?nbsp; 榪炵畫(huà)鐨刵涓猘tom鑳介噺鍊?浣垮叾鏈澶с?br>紼嬪簭涓璼umtemp錛宻um銆俿umtemp紜畾鐨勬槸鍏跺乏杈圭晫錛宻um紜畾鍏跺彸杈圭晫銆?br>sumtemp紜畾宸﹁竟鍓峮涓暟涔嬪拰涓鴻礋鐨勬渶澶х殑n錛屼笖絎琻涓暟鏄劇劧涓鴻礋錛岀劧鍚庝粠n+1寮濮嬮夋暟銆?br>sum紜畾浜?jiǎn)鍙宠竟鐣屼娇鍏舵渶澶с?br>姹傚拰鏈澶ч兘鍙互鐢ㄨ繖縐嶆濊礬錛侊紒錛侊紒錛侊紒錛侊紒錛侊紒
涓句緥
1錛?錛?4錛?錛?錛?2錛?錛?錛?6錛?錛?3錛?錛?0
璇風(fēng)湅sumt1=1,sum=1
sumt2=2;sum=1+2=3;
sum3=sum2-4=-1;鍒檚umtemp=0;sum涓嶅彉銆?br>sum4=sumtemp+4;sum<sum4,sum=4;
sum5=sumtemp+2錛泂um<sum5,sum=6
鎬諱箣sum鍙湁鍦╯um<sumtemp鏃舵墠淇敼銆俿umtemp<0鍒欐竻0.
涓緇磀p.
#include"stdio.h"
int main()
{
freopen("s.txt","r",stdin);
freopen("key.txt","w",stdout);
int n;
int a;
while(scanf("%ld",&n),n!=-1)
{
long long sum=-0x7fffffff,sumtemp=-0x7fffffff;
for(long i=0;i<n;i++)
{
scanf("%d",&a);
if(sumtemp>0)
sumtemp+=a;
else
sumtemp=a;
if(sumtemp>sum)
sum=sumtemp;
}
printf("%lld\n",sum);
}
return 0;
}
A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precisely one unit of time for being sold. A selling schedule is an ordered subset of products Sell ≤ Prod such that the selling of each product x∈Sell, according to the ordering of Sell, completes before the deadline dx or just when dx expires. The profit of the selling schedule is Profit(Sell)=Σx∈Sellpx. An optimal selling schedule is a schedule with a maximum profit.
For example, consider the products Prod={a,b,c,d} with (pa,da)=(50,2), (pb,db)=(10,1), (pc,dc)=(20,2), and (pd,dd)=(30,1). The possible selling schedules are listed in table 1. For instance, the schedule Sell={d,a} shows that the selling of product d starts at time 0 and ends at time 1, while the selling of product a starts at time 1 and ends at time 2. Each of these products is sold by its deadline. Sell is the optimal schedule and its profit is 80.
A set of products starts with an integer 0 <= n <= 10000, which is the number of products in the set, and continues with n pairs pi di of integers, 1 <= pi <= 10000 and 1 <= di <= 10000, that designate the profit and the selling deadline of the i-th product. White spaces can occur freely in input. Input data terminate with an end of file and are guaranteed correct.
For each set of products, the program prints on the standard output the profit of an optimal selling schedule for the set. Each result is printed from the beginning of a separate line.
4 50 2 10 1 20 2 30 1 7 20 1 2 1 10 3 100 2 8 2 5 20 50 10
80 185
The sample input contains two product sets. The first set encodes the products from table 1. The second set is for 7 products. The profit of an optimal schedule for these products is 185.
#include<iostream>
#include<cstdlib>
using namespace std;
#define MAX 10001
#define min(a,b) ((a)<(b) ? (a) : (b))
int father[MAX];
int p[MAX];
int result[MAX];
struct job{
int value;
int T;
}JOB[MAX];
bool operator <(job job1,job job2)
{
if(job1.value>job2.value)
return true;
else
return false;
}
int find(int x) //·µ»ØµÚ£Ø½ÚµãËùÊô¼¯ºÏµÄ¸ù½áµã
{
int px=x;
while(p[px]>=0)
px=p[px];
int tmp;
while(p[x]>=0)//ӦΪ³õֵΪ¸º
{
tmp=p[x];
p[x]=px;
x=tmp;
}
return px;
}
void UNION(int x,int y)
{
x=find(x);
y=find(y);
if(x==y)
return ;
int tmp=p[x]+p[y];
if(p[x]>p[y])
{
p[y]=tmp;
p[x]=y;
}
else
{
p[x]=tmp;
p[y]=x;
}
}
int main()
{
freopen("s.txt","r",stdin);
freopen("key.txt","w",stdout);
int num,temp=0;
while(cin>>num)
{
memset(result,0,num);
int i,l,j,k=0;
for( i=0;i<num;i++)
{
cin>>JOB[i].value>>JOB[i].T;
father[i]=i;
p[i]=-1;
}
sort(JOB,JOB+num);
for(i=0;i<num;i++)
{
j=find(min(JOB[i].T,num-1));//
if(father[j]!=0)
{
k++;
result[k]=i;
l=find(father[j]-1);
UNION(l,j);
father[j]=father[l];
}
}
i=0;
for(j=1;j<=k;j++)
{
i+=JOB[result[j]].value;}
cout<<i<<endl;
}
//system("PAUSE");
return 0;
}
瀵圭潃璇炬湰鍐欏緱錛岃嚜宸遍兘鐪嬩笉鎬庝箞鎳傘?/p>