HDOJ1015看懂題之後的簡單粗暴

來源:互聯網
上載者:User

標籤:acm   hdoj   

/*看懂題意之後,給定target和大寫字串,即是:把ABCDE……轉換為12345…… 在給定的不重複數之中找5個數,使得其滿足a-b^2+c^3-d^4+e^5等於給定的數target由於資料量不大,最大為20個不重複大寫字母,不多說,5重for迴圈搞定*/#include <iostream>#include <algorithm>#include <stdio.h>#include <math.h>#include <map>#include <set>#include <vector>#include <string>#include <cstring>#include <sstream>using namespace std;#define input freopen("input.txt","r",stdin);#define output freopen("output.txt","w",stdout);#define For1(i,a,b) for (i=a;i<b;i++)#define For2(i,a,b) for (i=a;i<=b;i++)#define Dec(i,a,b) for (i=a;i>b;i--)#define Dec2(i,a,b) for (i=a;i>=b;i--)#define Sca_d(x) scanf("%d",&x)#define Sca_s(x) scanf("%s",x)#define Sca_c(x) scanf("%c",&x)#define Sca_f(x) scanf("%f",&x)#define Sca_lf(x) scanf("%lf",&x)#define Fill(x,a) memset(x,a,sizeof(x))#define MAXN 0x7fffffffint a,b,c,d,e;int book[30];int ans[10];int main(){int x,i,j,k,l;char ch[20];while(cin>>x>>ch){if (!x) break;Fill(book,0);Fill(ans,0);l=strlen(ch);For1(i,0,l) book[ch[i]-64]++;//數字字元統計 For2(a,1,26)if (book[a])For2(b,1,26)if (a!=b&&book[b])For2(c,1,26)if (c!=a&&c!=b&&book[c])For2(d,1,26)if (d!=a&&d!=b&&d!=c&&book[d])For2(e,1,26)if (e!=a&&e!=b&&e!=c&&e!=d&&book[e])if (a-b*b+c*c*c-d*d*d*d+e*e*e*e*e==x)ans[1]=a,ans[2]=b,ans[3]=c,ans[4]=d,ans[5]=e;//直接暴力到最後一組 if (ans[1]==0)//如果直到搜尋完畢還沒有解的話,nocout<<"no solution";elseFor2(i,1,5)printf("%c",ans[i]+64);//記得將其轉換為字元輸出cout<<endl;}return 0;}

HDOJ1015看懂題之後的簡單粗暴

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.