HDU1248 1407 for迴圈暴力

來源:互聯網
上載者:User

           這兩題解題思想相同,貼在這做個對照。

           都是三重for自動計算。

 

          1248寒冰王座

/*給小費最少,買東西花費最多即可*/#include<iostream>using namespace std;int main(){int t,n;int a,b,c;cin>>t;while(t--){cin>>n;a=n/150;b=n/200;c=n/350;int max=-1;int tem;for(int i=0;i<=a;i++)   //完美的暴力{for(int j=0;j<=b;j++){for(int k=0;k<=c;k++){tem=150*i+200*j+350*k;if(max<tem && tem<=n)max=tem;}}}cout<<n-max<<endl;}return 0;}

             1407測試你是否和LTC一樣高

#include<iostream>#include<cmath>using namespace std;int main(){int a,b,c,n;while(cin>>n){a=sqrt(n*1.0);   //n轉換成double型b=a;c=a;int flag=0,flag_1=0,i,j,k;for(i=1;i<=a;i++){if(flag_1==1)break;for(j=1;j<=b;j++){if(flag==1){flag_1=1;i--;break;}for(k=1;k<=c;k++){if(i*i+j*j+k*k==n){flag=1;j--;break;}}}}cout<<i<<" "<<j<<" "<<k<<endl;}return 0;}

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.