codeforce 940D 思维题
2018-02-26 17:17
375 查看
传送门:http://codeforces.com/problemset/problem/940/D
For all 5 ≤ i ≤ n:
bi = 0 if ai, ai - 1, ai - 2, ai - 3, ai - 4 > r and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 1
bi = 1 if ai, ai - 1, ai - 2, ai - 3, ai - 4 < l and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 0
bi = bi - 1 otherwise
对于给定的a数组和b数组,找出其中一个l,r使得上述的条件满足。
(1)bi<=j<=i+4bi<=j<=i+4=00000
(2)bi<=j<=i+4bi<=j<=i+4=00001
(3)bi<=j<=i+4bi<=j<=i+4=11111
(4)bi<=j<=i+4bi<=j<=i+4=11110
对于(1)l<=MAXi<=j<=i+4ajl<=MAXi<=j<=i+4aj
对于(2)l>=MAXi<=j<=i+4aj+1l>=MAXi<=j<=i+4aj+1
对于(3)r>=MINi<=j<=i+4ajr>=MINi<=j<=i+4aj
对于(4)l>=MINi<=j<=i+4aj−1l>=MINi<=j<=i+4aj−1
题意:
b1 = b2 = b3 = b4 = 0.For all 5 ≤ i ≤ n:
bi = 0 if ai, ai - 1, ai - 2, ai - 3, ai - 4 > r and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 1
bi = 1 if ai, ai - 1, ai - 2, ai - 3, ai - 4 < l and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 0
bi = bi - 1 otherwise
对于给定的a数组和b数组,找出其中一个l,r使得上述的条件满足。
分析:
对于l,r有约束作用的只有以下的四种情况(1)bi<=j<=i+4bi<=j<=i+4=00000
(2)bi<=j<=i+4bi<=j<=i+4=00001
(3)bi<=j<=i+4bi<=j<=i+4=11111
(4)bi<=j<=i+4bi<=j<=i+4=11110
对于(1)l<=MAXi<=j<=i+4ajl<=MAXi<=j<=i+4aj
对于(2)l>=MAXi<=j<=i+4aj+1l>=MAXi<=j<=i+4aj+1
对于(3)r>=MINi<=j<=i+4ajr>=MINi<=j<=i+4aj
对于(4)l>=MINi<=j<=i+4aj−1l>=MINi<=j<=i+4aj−1
代码:
#include <iostream> #include <bits/stdc++.h> #define INF 1000000000 using namespace std; char b[100005]; int a[100005]; int main() { int n; cin>>n; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } scanf("%s",b); int x=0; //用于表示前5为数位 int l=-INF,r=INF; for(int i=4;i<n;i++) { x<<=1; x+=b[i]-'0'; x%=32; if(x==0) { int ma=-INF; for(int j=i;j>=i-4;j--) { ma=max(ma,a[j]); } l=min(l,ma); }else if(x==1){ int ma=-INF; for(int j=i;j>=i-4;j--) { ma=max(ma,a[j]+1); } l=max(l,ma); }else if(x==31){ int mi=INF; for(int j=i;j>=i-4;j--) { mi=min(mi,a[j]); } r=max(r,mi); }else if(x==30){ int mi=INF; for(int j=i;j>=i-4;j--) { mi=min(mi,a[j]-1); } r=min(r,mi); } } printf("%d %d",l,r); return 0; }
相关文章推荐
- Codeforce-839B Game of the Rows 思维
- codeforce 796 c Bank Hacking (思维题,分类讨论)
- codeforce 761E - Dasha and Puzzle(思维)
- Codeforce 839 -- B Game of the Rows 【思维 + 贪心】
- codeforce 675C Money Transfers (思维)
- Codeforce Flea CodeForces - 32C 规律|思维
- A. Carrot Cakes Codeforce 思维
- codeforce 557C Arthur and Table (思维)
- 【打渔】CodeForce Round 197 Div.2 Problem_A
- codeforces Karen and Coffee (区间贡献 思维)
- codeforce round 399# E
- CodeForce 510 B
- codeforce contest 103 problem D Time to Raid Cowavans(根号算法)
- Educational Codeforces Round 38 C. Constructing Tests 思维
- 【Codeforces Round 263 (Div 2)C】【贪心 哈弗曼思维】Appleman and Toastman 每个非1size子树延展为2子树的最大权
- codeforce 448C Painting Fence (贪心)
- codeforce 417D Cunning Gena (状压DP)
- Cut Ribbon codeforce
- Codeforce 762E.Radio stations-动态开点线段树 or CDQ分治
- codeforce 599C Day at the Beach