Codeforces Round #278 (Div. 1) 解题报告_html/css_WEB-ITnose

WBOY
풀어 주다: 2016-06-24 11:53:10
원래의
957명이 탐색했습니다.

A题:Fight the Monster

枚举+二分

因为每个元素的数据范围只有100,所以可以用枚举,对于血量用二分,然后判断结果是否可行。

代码如下:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;int hy, ay, dy, hm, am, dm;int bin_search(int a, int d){        if(d>=am) return hy;        int low=0, high=100000, mid, ans, c;        c=(hm+(a-dm-1))/(a-dm);        while(low>1;                if((mid+am-d-1)/(am-d)>c) {                        ans=mid;                        high=mid-1;                }                else                        low=mid+1;        }        return ans>hy?ans:hy;}int main(){        int h, a, d, i, j, min1, z;        while(scanf("%d%d%d",&hy,&ay,&dy)!=EOF) {                min1=INF;                scanf("%d%d%d",&hm,&am,&dm);                scanf("%d%d%d",&h,&a,&d);                for(i=0;i  <br> B题:  Strip  <p></p>  <p>线段树+DP+二分(或窗口滑动)</p>  <p>这题做了好长时间。。。终于AC了。。</p>  <p>基本思路是DP。DP[i]表示从第一个到第i个的最小可划分的区间数。然后对于每个数,找到前面可到达的最左端L,对于L的查找可用二分法或者滑动窗口法进行枚举查找,判断当前枚举区间是否可行的时候用线段树对当前区间的最值进行查询。状态转移方程dp[i]=min(dp[L],....,dp[i-lenth])+1;然后对于dp[L]...dp[i-lenth]这段区间查最值可用另一棵线段树在logn的时间内查询。所以需要建两棵线段树。</p>  <p>话说最近换了代码风格。。看起来果然比以前的好看多了。。。</p>  <p>代码如下:</p>  <p></p>  <pre name="code" class="sycode">#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;#define lson l, mid, rt>1;        if(p=r) {                if(q==1) {                        q_minv=min(q_minv,minv[rt]);                        q_maxv=max(q_maxv,maxv[rt]);                } else                        q_mindp=min(q_mindp,mindp[rt]);                return ;        }        int mid=l+r>>1;        if(llmid) Query(q,ll,rr,rson);}int bin_search(int r){        int low=1, high=r, mid, ans=-1;        while(low>1;                q_maxv=-INF; q_minv=INF;                Query(1,mid,r,root);                //if(r==4)                //printf("%d %d\n",q_minv,q_maxv);                if(q_maxv-q_minvi) continue ;                q_mindp=INF;                //printf("%d %d\n",l,i-lenth);                Query(-1,l-1,i-lenth,root);                if(q_mindp==INF) continue ;                Update(-1,i,q_mindp+1,root);        }        q_mindp=INF;        Query(-1,n,n,root);        printf("%d\n",q_mindp==INF?-1:q_mindp);        return 0;}</algorithm></set></map></queue></ctype.h></math.h></stdlib.h></cstring></string></cstdio></iostream>
로그인 후 복사


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!