首屆華中區程式設計邀請賽暨第十屆武漢大學程式設計大賽網路預賽A題(HDOJ-4215)

來源:互聯網
上載者:User

       比賽的時候最後時間專註1010去了..最後十分鐘才想起1001應該能打表..結果沒搞得贏..賽後果斷AC阿...這題..好噁心..

       其實對於這一類的N很大的問題..就要有大表找規律的思維..或者找到通項公式..或者找到遞推關係利用矩陣乘法..而本題就是..N<=30時暴力枚舉出結果..N>30...結果都是10...囧...

Program:

#include<iostream>#include<string.h>#include<stdio.h>#include<algorithm>#include<math.h>#include<queue>using namespace std; int f[35],e[35],s[35],i,j,k,m,N,ans,l,r,m1,m2,T,t; int gcd(int a,int b){      if (!b) return a;      return gcd(b,a%b);}int main(){         memset(e,0,sizeof(e));      for (i=1;i<=31;i++)         for (j=1;j<=i;j++)            if (gcd(i,j)==1) e[i]++;      memset(f,0,sizeof(f));      for (i=1;i<=31;i++)         for (j=1;j<=i;j++)           if (i%j==0) f[i]++;      for (N=1;N<=31;N++)      {            ans=0;            for (l=1;l<=N;l++)               for (r=l;r<=N;r++)               {                      m1=m2=0;                      for (i=l;i<=r;i++)                       {                            m1+=e[i];                            m2+=f[i];                      }                      if (m1==m2) ans++;               }            s[N]=ans;      }      scanf("%d",&T);      for (t=1;t<=T;t++)      {            scanf("%d",&i);            printf("Case %d: ",t);            if (i<=30) printf("%d\n",s[i]);              else printf("10\n");      }      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.