Codeforces Round #278 (Div. 2)

A直接暴力好了。

 1 #include<bits/stdc++.h>
 2 typedef long long ll;
 3 using namespace std;
 4
 5 int pan(ll x)
 6 {
 7     while (x)
 8     {
 9         if (x%10==8) return 1;
10         x/=10;
11     }
12     return 0;
13 }
14
15 int main()
16 {
17     ll n;
18     cin>>n;
19     for (int i=1;i<=10000;i++)
20     if (pan(abs(n+i)))
21     {
22         cout<<i;
23         return 0;
24     }
25     return 0;
26 }

B:处理起来比较蛮烦,或则我比较懒。

大概思路是:先判n==4

2:n==0,预设定一个数。

3:N==1,可以用数学算出来;

N==2&&N==3的情况比较难讨论。但是ai<=500;看到直接暴力的思路;

C:暴力即可。

我们知道所有值都在100以内。所以我们可以暴力攻击和防御值买多少,然后算HP。因为HP可能买很多。

这样循环数不会很多。

 1 #include<bits/stdc++.h>
 2 typedef long long ll;
 3 using namespace std;
 4
 5 int hpy,atky,defy;
 6 int hpm,atkm,defm;
 7
 8
 9
10 int pan(int b,int c)
11 {
12
13        int tatky=atky+b;
14        int tdefy=defy+c;
15        if (tatky<=defm) return -1;
16
17        int tmp=tatky-defm;
18
19        int ti=hpm/tmp;
20        if (hpm%tmp) ti++;
21
22        if (atkm<=tdefy) return 0;
23
24        tmp=atkm-tdefy;
25
26        if (ti*tmp<hpy) return 0;
27        return ti*tmp-hpy+1;
28 }
29
30
31 int main()
32 {
33
34     int h,a,d;
35     cin>>hpy>>atky>>defy;
36     cin>>hpm>>atkm>>defm;
37     cin>>h>>a>>d;
38
39     int ans=1<<30;
40
41
42     for (int j=0;j<4000;j++)
43     for (int k=0;k<4000;k++)
44     {
45       if (pan(j,k)==-1) continue;
46       ans=min(ans,pan(j,k)*h+a*j+d*k);
47     }
48
49     cout<<ans<<endl;
50     return 0;
51     }

D:思路很多:线段树,单调队列。

我看到的一种做法。。。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 int a[123456];
 5 int n,L,s;
 6 int flag=1;
 7 int main()
 8 {
 9     int left,right;
10     int ans=0;
11     cin>>n>>s>>L;
12     int last=0;
13     for (int i=0;i<n;i++) cin>>a[i];
14
15      int pos=0;
16      for (;pos<n;pos++)
17      {
18          int maxm,minm;
19          int cnt=1;
20          maxm=minm=a[pos];
21          right=pos+1;
22          while (right<n)
23          {
24              maxm=max(maxm,a[right ]);
25              minm=min(minm,a[right ]);
26              if (maxm-minm<=s) cnt++;
27              else break;
28              right++;
29          }
30          right--;
31
32          maxm=minm=a[pos];
33          left=pos-1;
34          while (left>=last)
35          {
36              maxm=max(maxm,a[left ]);
37              minm=min(minm,a[left ]);
38              if (maxm-minm<=s) cnt++;
39              else break;
40              left--;
41          }
42          left++;
43          if (cnt<L)
44          {
45             flag=0;
46             break;
47          }
48          ans++;
49          last=left+L;
50          pos=right;
51      }
52
53      if (flag==0) ans=-1;
54      cout<<ans;
55      return 0;
56 }

http://www.cnblogs.com/AOQNRMGYXLMV/p/4116052.html。

这里有讲解。

然后我再分析一下

7 2 21 3 1 2 4 1 2样例:先把1 3 1 2放入第一组。last的值是3(下标从0开始);下次循环时可以在left到last中再找,就是4,2两个数一组。
时间: 2024-08-03 11:11:15

Codeforces Round #278 (Div. 2)的相关文章

Codeforces Round #278 (Div. 2) b

/**  *  * @brief Codeforces Round #278 (Div. 2) b  * @file b.c  * @author mianma  * @created 2014/11/24 17:52  * @edited  2014/11/18 17:52  * @type brute  *   * @note   *          declare k >= 0;  *              then   *                  x1 = k  *   

Codeforces Round #278 (Div. 2) d

/**  * @brief Codeforces Round #278 (Div. 2) d  * @file d.c  * @author 面码  * @created 2014/11/26 10:07  * @edited  2014/11/26 10:07  * @type dp   * @note  *      自己的TL了,看了别人代码写的  *      该代码主要是在dp的基础上使用stl来提速  *      dp需辅助提速,但内存又不能爆掉是该题目的卡点 = =  */ #i

Codeforces Round #278 (Div. 2) c

/**  * @brief Codeforces Round #278 (Div. 2) c  * @file c.c  * @author 面码  * @created 2014/11/25 14:15  * @edited  2014/11/25 14:15  * @type brute  *  */ #include <stdio.h> #define max(a, b)  ((a) > (b) ? (a) : (b)) #define min(a, b)  ((a) > (

Codeforces Round #278 (Div. 1)

A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's H

CodeForces Round #278 (Div.2) (待续)

A 这么简单的题直接贴代码好了. 1 #include <cstdio> 2 #include <cmath> 3 using namespace std; 4 5 bool islucky(int a) 6 { 7 a = abs(a); 8 while(a) 9 { 10 if(a % 10 == 8) return true; 11 a /= 10; 12 } 13 return false; 14 } 15 16 int main(void) 17 { 18 int a,

Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]

哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058                 2014-11-22 06:52:58     njczy2010     B - Candy Boxes             GNU C++     Accepted 31 ms 4 KB 8795016                 2014-11-22 06:48:15     njczy2010     B - Candy Boxes             GNU C+

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿