2016 HHU新生赛业余组 题解


A题 一句话说三遍

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. using namespace std;  
  3.   
  4. int main()  
  5. {  
  6.     cout<<"A man can be destroyed but not defeated."<<endl;  
  7.     cout<<"A man can be destroyed but not defeated."<<endl;  
  8.     cout<<"A man can be destroyed but not defeated."<<endl;  
  9.     return 0;  
  10. }  


B题 求2的n次方

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<cmath>  
  4. using namespace std;  
  5.   
  6. int main()  
  7. {  
  8.     int n;  
  9.     while(cin>>n)  
  10.     {  
  11.         cout<<pow(2,n)<<endl;  
  12.     }  
  13.     return 0;  
  14. }   


C题 求阶乘之和

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<cmath>  
  4. using namespace std;  
  5.   
  6. long long jiecheng(int n)  
  7. {  
  8.     int res=1;  
  9.     for(int i=1;i<=n;i++)  
  10.     {  
  11.         res=res*i;  
  12.     }  
  13.     return res;  
  14. }  
  15.   
  16.   
  17. int main()  
  18. {  
  19.     int n;  
  20.     while(cin>>n)  
  21.     {  
  22.         long long sum=0;  
  23.         for(int i=1;i<=n;i++)  
  24.         {  
  25.             sum+=jiecheng(i);  
  26.         }  
  27.         cout<<sum<<endl;  
  28.     }  
  29.     return 0;  
  30. }   


D题 普通排序

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<algorithm>  
  4. #include<cmath>  
  5. using namespace std;  
  6.   
  7. int a[102];  
  8.   
  9. int main()  
  10. {  
  11.     int n;  
  12.     cin>>n;  
  13.     for(int i=0;i<n;i++)  
  14.     {  
  15.         cin>>a[i];   
  16.     }  
  17.     sort(a,a+n);  
  18.     for(int i=0;i<n;i++)  
  19.     {  
  20.         cout<<a[i]<<endl;   
  21.     }  
  22.     return 0;  
  23. }   


E题 闰年问题

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<algorithm>  
  4. #include<cmath>  
  5. using namespace std;  
  6.   
  7. int main()  
  8. {  
  9.     int l,r;  
  10.     cin>>l>>r;   
  11.     for(int i=l;i<=r;i++)  
  12.     {  
  13.         if(i%4==0&&i%100!=0||i%400==0)  
  14.         cout<<i<<endl;  
  15.     }  
  16.     return 0;  
  17. }   


F题 HHUOJ 1001 汽水瓶 (水题)

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. #include<cstdio>  
  3. using namespace std;  
  4.    
  5. int main()  
  6. {  
  7.     int num;   
  8.     int t;  
  9.     cin>>t;  
  10.     while(t--)  
  11.     {  
  12.         scanf("%d",&num);  
  13.         int cnt=0;  
  14.         while(num>=0)  
  15.         {  
  16.             num=num-3+1;  
  17.             if(num>=0)  
  18.             cnt++;  
  19.         }  
  20.         cout<<cnt<<endl;          
  21.     }  
  22.       
  23.     return 0;  
  24. }   


G题 HHUOJ 1015 圆上的点点点点点点点点点点点点点点(根号优化计算)

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>    
  2. #include<cmath>  
  3. #include<cstdio>    
  4. using namespace std;    
  5.      
  6. int main()    
  7. {       
  8.     long int S;    
  9.     int t;  
  10.     cin>>t;  
  11.     while(t--)  
  12.     {  
  13.         scanf("%d",&S);     
  14.         double s=sqrt(S);    
  15.         int num=0;    
  16.         for(int i=1;i<s;i++)    
  17.         {    
  18.             int j=sqrt((S-i*i));    
  19.             if(i*i+(j+1)*(j+1)==S)num++;    
  20.             if(i*i+(j)*(j)==S)num++;    
  21.             if(i*i+(j-1)*(j-1)==S)num++;    
  22.                  
  23.         }    
  24.         if(s!=int(s))cout<<num*4<<endl;    
  25.         else cout<<num*4+4<<endl;    
  26.     }    
  27. }    


H题 循环

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>    
  2. #include<cmath>  
  3. #include<cstdio>    
  4. using namespace std;    
  5.   
  6. int main()  
  7. {  
  8.     int cnt=0;  
  9.     int n;  
  10.     cin>>n;  
  11.     while(n!=1)  
  12.     {  
  13.         if(n%2==1)  
  14.         {  
  15.             n=n*3+1;  
  16.         }   
  17.         else  
  18.         {  
  19.             n=n/2;  
  20.         }  
  21.         cnt++;  
  22.     }  
  23.     cout<<cnt<<endl;  
  24.     return 0;  
  25. }   


I题 质数的朴素算法

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>    
  2. #include<cmath>  
  3. #include<cstdio>    
  4. using namespace std;    
  5.   
  6. int main()  
  7. {  
  8.     int l,r;  
  9.     cin>>l>>r;  
  10.     for(int i=l;i<=r;i++)  
  11.     {  
  12.         bool flag=true;  
  13.         for(int j=2;j<=sqrt(i);j++)  
  14.         {  
  15.             if(i%j==0)  
  16.             {  
  17.                 flag=false;  
  18.                 break;  
  19.             }     
  20.         }  
  21.         if(flag==true&&i!=1)  
  22.         cout<<i<<endl;  
  23.     }  
  24.     return 0;  
  25. }   


J题 快速排序

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<algorithm>  
  4. #include<cmath>  
  5. using namespace std;  
  6.   
  7. int a[1000000+2];  
  8.   
  9. int main()  
  10. {  
  11.     int n;  
  12.     scanf("%d",&n);  
  13.     for(int i=0;i<n;i++)  
  14.     {  
  15.         scanf("%d",&a[i]);  
  16.     }  
  17.     sort(a,a+n);  
  18.     for(int i=0;i<n;i++)  
  19.     {  
  20.         printf("%d\n",a[i]);  
  21.     }  
  22.     return 0;  
  23. }   


K题 数据的预处理

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<algorithm>  
  4. #include<cmath>  
  5. using namespace std;  
  6.   
  7. int a[5000+5];   
  8.   
  9. int main()  
  10. {  
  11.     int t;  
  12.       
  13.     int cnt=0;  
  14.     for(int i=1;i<=5000;i++)  
  15.     {  
  16.          if(i%4==0&&i%100!=0||i%400==0)  
  17.          {  
  18.             cnt++;  
  19.          }  
  20.          a[i]=cnt;  
  21.     }  
  22.       
  23.     scanf("%d",&t);  
  24.     while(t--)  
  25.     {  
  26.         int l,r;  
  27.         scanf("%d%d",&l,&r);  
  28.         int num=a[r]-a[l];  
  29.         if(l%4==0&&l%100!=0||l%400==0)num++;  
  30.         printf("%d\n",num);  
  31.     }  
  32.       
  33.     return 0;     
  34. }   
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务