Codeforces round #267 (Div. 2)

Source: Internet
Author: User
Tags cmath

Qaqaqaqaq

D questions Sb was not written out (heavy fog)

Qaqaqaq

Close ratingqaq

Question C: Can I use wa multiple times? I just need to make a wrong Max transfer! Qaq

 

A. George and accommodation

A and B ask if A is less than or equal to B-2

This...

#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <algorithm>#include <queue>using namespace std;#define rep(i, n) for(int i=0; i<(n); ++i)#define for1(i,a,n) for(int i=(a);i<=(n);++i)#define for2(i,a,n) for(int i=(a);i<(n);++i)#define for3(i,a,n) for(int i=(a);i>=(n);--i)#define for4(i,a,n) for(int i=(a);i>(n);--i)#define CC(i,a) memset(i,a,sizeof(i))#define read(a) a=getint()#define print(a) printf("%d", a)#define dbg(x) cout << #x << " = " << x << endl#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<‘0‘||c>‘9‘; c=getchar()) if(c==‘-‘) k=-1; for(; c>=‘0‘&&c<=‘9‘; c=getchar()) r=r*10+c-‘0‘; return k*r; }inline const int max(const int &a, const int &b) { return a>b?a:b; }inline const int min(const int &a, const int &b) { return a<b?a:b; }int main() {int n=getint(), ans=0;while(n--) {int a=getint(), b=getint();if(b-2>=a) ++ans;}print(ans);return 0;}

 

B. Fedor and new game

Q: I will give you m + 1 count so that you can determine whether the binary form of the given number is smaller than or equal to k in number m + 1.

Can you try again ..

#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <algorithm>#include <queue>using namespace std;#define rep(i, n) for(int i=0; i<(n); ++i)#define for1(i,a,n) for(int i=(a);i<=(n);++i)#define for2(i,a,n) for(int i=(a);i<(n);++i)#define for3(i,a,n) for(int i=(a);i>=(n);--i)#define for4(i,a,n) for(int i=(a);i>(n);--i)#define CC(i,a) memset(i,a,sizeof(i))#define read(a) a=getint()#define print(a) printf("%d", a)#define dbg(x) cout << #x << " = " << x << endl#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<‘0‘||c>‘9‘; c=getchar()) if(c==‘-‘) k=-1; for(; c>=‘0‘&&c<=‘9‘; c=getchar()) r=r*10+c-‘0‘; return k*r; }inline const int max(const int &a, const int &b) { return a>b?a:b; }inline const int min(const int &a, const int &b) { return a<b?a:b; }const int N=1005;int a[N], my, ans;int main() {int n=getint(), m=getint(), k=getint();for1(i, 1, m) read(a[i]);read(my);for1(i, 1, m) {int tot=0;for3(j, n-1, 0) {if(((1<<j)&a[i])!=((1<<j)&my)) ++tot;}if(tot<=k) ++ans;}print(ans);return 0;}

 

C. George and job

Question: give you n numbers, let you divide K blocks into M contiguous blocks, and then calculate the maximum value of all feasible solutions.

If d [I, j] is set, it indicates the maximum number of I segments divided into J blocks.

D [I, j] = max {d [K, J-1]} + sum [I-m, I], 1 <= k <= I-m

The answer is max {d [I, K]}.

Here is n ^ 3. We want to optimize horizontal n ^ 2.

Set MX [I, j] to max {d [K, J]} 1 <= k <= J

Then transfer

D [I, j] = Mx [I-m, J-1] + sum [I-m, I]

The MX transfer is

MX [I, j] = max {MX [I-1, J], d [I, j]}

#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <algorithm>#include <queue>using namespace std;typedef long long ll;#define rep(i, n) for(int i=0; i<(n); ++i)#define for1(i,a,n) for(int i=(a);i<=(n);++i)#define for2(i,a,n) for(int i=(a);i<(n);++i)#define for3(i,a,n) for(int i=(a);i>=(n);--i)#define for4(i,a,n) for(int i=(a);i>(n);--i)#define CC(i,a) memset(i,a,sizeof(i))#define read(a) a=getint()#define print(a) printf("%I64d", a)#define dbg(x) cout << #x << " = " << x << endl#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }inline const ll getint() { ll r=0, k=1; char c=getchar(); for(; c<‘0‘||c>‘9‘; c=getchar()) if(c==‘-‘) k=-1; for(; c>=‘0‘&&c<=‘9‘; c=getchar()) r=r*10+c-‘0‘; return k*r; }inline const ll max(const ll &a, const ll &b) { return a>b?a:b; }inline const ll min(const ll &a, const ll &b) { return a<b?a:b; }const int N=5005;int n, m, k;ll sum[N], d[N], ans, mx[N][N], f[N], a[N];int main() {read(n); read(m); read(k);for1(i, 1, n) read(a[i]), sum[i]=sum[i-1]+a[i];for1(i, m, n) d[i]=sum[i]-sum[i-m];for1(i, m, n) {for3(j, k, 1) {f[j]=mx[i-m][j-1]+d[i];mx[i][j]=max(mx[i-1][j], f[j]);}ans=max(ans, f[k]);}print(ans);return 0;}

 

D. Fedor and essay

String question, it's time for class. Come back to make up at noon ..

 

Codeforces round #267 (Div. 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.