Codeforces Round #260 (Div. 2)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   for   ar   

題目連結

B Fedya and Maths

按照題目的公式求數,有一個規律4的倍數為4,然後就是大數模數,但是我還二的

把strlen(s)放到了迴圈上,導致了每次迴圈都要算一次,最後逾時。本來很簡單的,, 簡直慘。。。

 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstdio> 6 #include <vector> 7 #include <algorithm> 8 #define LL long long 9 const int maxn = 100000+10;10 using namespace std;11 int ans;12 char s[maxn];13 int num[maxn];14 15 int main()16 {17     int i, j, x, len;18     while(~scanf("%s", s))19     {20         len = strlen(s);21         for(i = 0; i < len; i++)22         num[i] = s[i]-48;23         x = 0;24         for(i = 0; i < len; i++)25         {26             x = (x*10+num[i])%4;27         }28         if(x==0)29         cout<<4<<endl;30         else31         cout<<0<<endl;32     }33     return 0;34 }

C Boredom

每次找一個數,但要刪除和它數字差一的數字,然後這個數字是得分,求最大 的得分。

分析:剛開始有思路,就亂搞了一下,結果最後判的時候超記憶體了。。。。

其實應該是dp【】,d[i] 表示到i個數為止的最大值,每次都是取間隔的一個和間隔兩個的最大值。

下面是代碼,判斷條件有點多,代碼可以更簡化的。。。

 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstdio> 6 #include <vector> 7 #include <queue> 8 #include <algorithm> 9 #define LL __int6410 const int maxn = 100000+10;11 using namespace std;12 LL d[maxn], h[maxn], ans;13 int n;14 15 int main()16 {17     int i, a;18     while(~scanf("%d", &n))19     {20         memset(h, 0, sizeof(h));21         memset(d, 0, sizeof(d));22         for(i = 0; i < n; i++)23         {24             scanf("%d", &a);25             h[a] ++;26         }27         ans = 0;28         d[1] = h[1];29         d[2] = 2*h[2];30         d[3] = 3*h[3]+d[1];31         ans = d[1];32         ans = max(d[2], ans);33         ans = max(d[3], ans);34         for(i = 4; i <= 100000; i++)35         {36             if(h[i]==0)37             d[i] = ans;38             else39             {40                 d[i] = (LL)h[i]*i+max(d[i-2], d[i-3]);41                 if(h[i-1]==0)42                 d[i] = max(d[i], d[i-1]+i*h[i]);43             }44             if(d[i]>ans) ans = d[i];45         }46         printf("%I64d\n", ans);47     }48     return 0;49 }

 

聯繫我們

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