分析:开始从v0开始,每天增加a,然后超过v1就从v1开始
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "string" 5 using namespace std; 6 int c,v0,v1,a,l; 7 int main() 8 { 9 cin>>c>>v0>>v1>>a>>l; 10 if(c==0){ 11 cout<<"0"<<endl; 12 }else{ 13 c=max(0,c-v0); 14 int k=1; 15 while(c>0){ 16 c+=l; v0=min(v0+a,v1); 17 c-=v0; k++; 18 } 19 cout<<k<<endl; 20 } 21 return 0; 22 }
分析:先求出正n变形的每个内角多少度,然后在把这个角分成n-2份,依次看取其中几份的时候绝对值的差最小即可
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "string" 5 #include "cmath" 6 #define eps 1e-9 7 using namespace std; 8 const double INF=200.0; 9 double n,B; 10 int main() 11 { 12 cin>>n>>B; 13 int num=n-2; 14 int k; 15 double ans=INF; 16 double tt=(double)((n-2)*180.0/(double)n); 17 tt/=num; 18 for(int i=1;i<=num;i++){ 19 double res=tt*(double)i; 20 if(fabs(res-(double)B)<ans){ 21 ans=fabs(res-(double)B); 22 k=i+2; 23 } 24 } 25 cout<<"2 "<<"1 "<<k<<endl; 26 return 0; 27 }