Codeforces Round #105
B - Escape
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*
*/
int main()
{
double vp,vd,t,f,c;//都要设为double型,刚开始用了int就不对
cin>>vp>>vd>>t>>f>>c;
if(vp>=vd)
cout<<0<<endl;
else
{
double ps=0,ds=0,ff=0;
int ci=0;
double time=1;
ps+=vp*t;//公主第一个t逃跑距离
while(1)
{
double x=ps/(vd-vp);//龙追上女孩要用的时间
//追上以后要从0开始追,所以每一段距离都是ps
ps+=x*vp;
if(ps>=c)break;
else
{
ci++;
ps+=(x+f)*vp;//龙回到原点的时间加上f这段时间
}
}
cout<<ci<<endl;
}
}
C - Terse princess
没过
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*
Input
10 2 3
Output
5 1 3 6 16 35 46 4 200 99
10 9 8 7 6
Input
5 0 0
Output
10 10 6 6 5
*/
int main()
{
int n,a,b;
cin>>n>>a>>b;
if(n<a+b)
{
cout<<"-1"<<endl;
}
else
{
int s=0;
cout<<n+1;
a++;
int j=n+1,k=n+1;
int x=n-a-b;
for(int i=1; i<n; i++)
{
if(x>0)
{
j--;
s+=j;
x--;
}
else if(a>0)
{
k++;
j=k;
s+=j;
a--;
}
else if(b>0)
{
j=s+1;
s+=j;
b--;
}
cout<<" "<<j;
}
}
}
C - Terse princess
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*
10 2 3
1 2 4 8 9 10 10 10 10 10
w w w o o
注意第二个数如果大于第一个就一定是wow而不是oh,因为它大于前面的和,所以构造时先排wow
刚开始自己是这样构造的:
1 1 1 1 1 2 3 11 22 44
这样的话就要考虑上面说的那种情况,当n=5,a=4,b=0这种情况时会输出1 2 3 4 5,这样就不对了(1后面跟2应该是wow
*/
int main()
{
int n,a,b;
cin>>n>>a>>b;
int k=1,s=1;
int x[n];
x[1]=1;//先用数组存数列最后一起输出更方便
for(int i=2; i<=n; i++)
{
if(b)
{
k=s+1;
b--;
}
else if(a&&i>2)
{
k++;
a--;
}
x[i]=k;
s+=k;
}
if(a||b)
{
cout<<"-1"<<endl;
}
else
{
for(int i=1; i<=n; i++)
{
if(i!=n)
cout<<x[i]<<" ";
else
cout<<x[i]<<endl;
}
}
}

浙公网安备 33010602011771号