Codeforces Round #298 (Div. 2)

來源:互聯網
上載者:User

標籤:

A - Exam 構造

 1 #include <cstdio> 2  3 int ans[5000 + 5]; 4  5 int main() { 6     int n, cnt = 1; 7     scanf("%d", &n); 8     for (int i = 1; i <= n; i++) { 9         if (i&1) ans[i] = cnt;10         else {11             ans[i] = n+1-cnt;12             cnt++;13         }14     }15     ans[0] = ans[n];16     if (n == 1 || n == 2) {17         printf("1\n1\n");18         return 0;19     }20     if (n == 3) {21         printf("2\n1 3\n");22         return 0;23     }24     printf("%d\n", n);25     for (int i = 0; i < n; i++)26         printf("%d ", ans[i]);27     return 0;28 }
View Code

B - Covered Path 想法題

 1 #include <cstdio> 2  3 inline int min(int a, int b) { 4     return a < b ? a : b; 5 } 6  7 int main() { 8     int v1, v2, t, d; 9     scanf("%d%d%d%d", &v1, &v2, &t, &d);10     int ans =  0;11     for (int i = 0; i < t; i++)12         ans += min(v1+i*d, v2+(t-i-1)*d);13     printf("%d\n", ans);14     return 0;15 }
View Code

C - Polycarpus‘ Dice 求上下界

 1 #include <cstdio> 2  3 const int N = 100000*2 + 5; 4 typedef long long ll; 5 ll ans[N], num[N], suf[N], pre[N]; 6  7 int main() { 8     int n; 9     ll s;10     scanf("%d%lld", &n, &s);11     for (int i = 1; i <= n; i++)12         scanf("%lld", num+i);13     for (int i = 1; i <= n; i++)14         pre[i] = pre[i-1] + num[i];15     for (int i = n; i >= 1; i--)16         suf[i] = suf[i+1] + num[i];17     ll can_min, can_max;18     for (int i = 1; i <= n; i++) {19         can_min = s - pre[i-1] - suf[i+1];20         if (can_min < 1) can_min = 1;21         can_max = s - n + 1;22         if (can_max > num[i]) can_max = num[i];23         ans[i] = num[i] - (can_max - can_min + 1);24     }25     for (int i = 1; i <= n; i++)26         printf("%lld ", ans[i]);27     return 0;28 }
View Code

 

Codeforces Round #298 (Div. 2)

聯繫我們

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