檔案
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, w1 ,w2, h1, h2;
cin >> n >> w1 >> w2 >> h1 >> h2;
float water[n];
for(int i = 0 ; i < n ; i++ )
{
cin >> water[i];
}
int block = 0; //現在在哪塊
float a1 = w1 * w1, a2 = w2 * w2;
int hlist[n] , x = 0 ; //x為現在哪杯水,哪個hlist
while(true)
{
if(x == n) break;
if(block == 0)
{
if( h1 + (water[x] / a1 - h1) * a1 / a2 > h1 + h2)
{
hlist[x] = h1 + h2;
break;
}
else if(water[x] / a1 < h1)
{
hlist[x] = water[x] / a1;
h1 = h1 - hlist[x];
}
else
{
hlist[x] = h1 + ( (water[x] / a1 - h1) * a1 / a2 );
h2 = h2 - ( hlist[x] - h1 );
block = 1;
}
}
else
{
if(water[x] / a2 < h2)
{
hlist[x] = water[x] / a2;
h2 = h2 - hlist[x];
}
else
{
hlist[x] = h2;
break;
}
}
x += 1;
}
sort(hlist, hlist + x, greater<int>());
cout << hlist[0];
}
檔案
#includeusing namespace std;
int main()
{
int n, w1 ,w2, h1, h2;cin >> n >> w1 >> w2 >> h1 >> h2;
float water[n];
for(int i = 0 ; i < n ; i++ )
{
cin >> water[i];
}int block = 0; //現在在哪塊
float a1 = w1 * w1, a2 = w2 * w2;
int hlist[n] , x = 0 ; //x為現在哪杯水,哪個hlist
while(true)
{if(x == n) break;
if(block == 0)
{
if( h1 + (water[x] / a1 - h1) * a1 / a2 > h1 + h2)
{
hlist[x] = h1 + h2;break;
}
else if(water[x] / a1 < h1)
{
hlist[x] = water[x] / a1;h1 = h1 - hlist[x];
}
else
{
hlist[x] = h1 + ( (water[x] / a1 - h1) * a1 / a2 );h2 = h2 - ( hlist[x] - h1 );
block = 1;
}
}
else
{
if(water[x] / a2 < h2)
{
hlist[x] = water[x] / a2;h2 = h2 - hlist[x];
}
else
{
hlist[x] = h2;break;
}}
x += 1;
}sort(hlist, hlist + x, greater());
cout << hlist[0];
}
break之前要把x+1,不然排序時不會算到最後一個加入的
檔案
#includeusing namespace std;
int main()
{
int n, w1 ,w2, h1, h2;cin >> n >> w1 >> w2 >> h1 >> h2;
float water[n];
for(int i = 0 ; i < n ; i++ )
{
cin >> water[i];
}int block = 0; //現在在哪塊
float a1 = w1 * w1, a2 = w2 * w2;
int hlist[n] , x = 0 ; //x為現在哪杯水,哪個hlist
while(true)
{if(x == n) break;
if(block == 0)
{
if( h1 + (water[x] / a1 - h1) * a1 / a2 > h1 + h2)
{
hlist[x] = h1 + h2;break;
}
else if(water[x] / a1 < h1)
{
hlist[x] = water[x] / a1;h1 = h1 - hlist[x];
}
else
{
hlist[x] = h1 + ( (water[x] / a1 - h1) * a1 / a2 );h2 = h2 - ( hlist[x] - h1 );
block = 1;
}
}
else
{
if(water[x] / a2 < h2)
{
hlist[x] = water[x] / a2;h2 = h2 - hlist[x];
}
else
{
hlist[x] = h2;break;
}}
x += 1;
}sort(hlist, hlist + x, greater());
cout << hlist[0];
}
break之前要把x+1,不然排序時不會算到最後一個加入的
不包含x==n的break