跳过正文
  1. Posts/

cf 534B. Covered Path

·1 分钟

http://codeforces.com/problemset/problem/534/B

题意是说一辆车,每秒内的速度恒定…第I秒到第I+1秒的速度变化不超过D。初始速度为V1,末速度为V2,经过时间t,问最远能走多远。

策略就是尽可能加速…加到某个时间,如果在这个时间不开始减速就回不到V2了。

从后往前预处理下每秒钟能达到的最大速度(如果超过这个速度,将不能减回到V2)

 1
 2    /* ***********************************************
 3    Author :111qqz
 4    Created Time :2016年02月22日 星期一 23时49分32秒
 5    File Name :code/cf/problem/534B.cpp
 6    ************************************************ */
 7
 8    #include <iostream>
 9    #include <cmath>
10    #include <cstring>
11    #include <algorithm>
12
13    using namespace std;
14    const int N=1E2+5;
15    const int inf=8E9;
16    int a[N],m[N];
17    int v1,v2,t,d,tmp,p,ans,n;
18
19
20    int main()
21    {
22        cin>>v1>>v2>>t>>d;
23        p = inf;
24        memset(a,0,sizeof(a));
25        a[1]= v1;
26        tmp = v2;
27        m[t]= v2;
28        for ( int i = t-1 ; i >= 1; i--)
29        {
30            tmp = tmp+d;
31            m[i] = tmp;
32        }
33        for ( int i =2 ;i <= t; i++ )
34        {
35            if (a[i-1]+d<=m[i])
36            {
37                a[i] = a[i-1] + d;
38            }
39            else
40            {
41                a[i] = m[i];
42                p = i;
43                break;
44            }
45        }
46        ans = 0;
47        for ( int i = p ; i <= t; i++ )
48            a[i] = m[i];
49        for ( int i = 1; i <= t ; i++ )
50        {
51            if (i<p)
52                ans = ans + a[i];
53            else ans = ans + m[i];
54        }
55       // for ( int i = 1; i <= t ; i++)
56       //     cout<<"a[i]:"<<a[i]<<endl;
57        cout<<ans<<endl;
58
59        return 0;
60    }

相关文章

hdu 2138 How many prime numbers

ACM STEPS里的…这题前面一道是求LCM….结果接下来就是这么一道。。。 朴素会超….筛法会爆….题目顺序真是按照难度来的? 于是想到 Miller-Rabin素数测试……. 这个方法是基于费马小定理 我的理解就是… 如果我要判断n是否为素数 只要取k个数 如果满足 a^(n-1)mod n =1 那么n就很可能为素数。 证明什么的…暂时还是算了吧…论文里貌似扯了一大堆 第一次用,竟然真的A了。。。。 感觉更好的办法也许是先打一个比较小的素数表,然后每次random选取若干个进行判断…那样应该更可靠些? 本来想WA掉之后再改的。。。没想到这么写就A掉了。。。。杭电数据略水?

cf 535B Tavas and SaDDas

·1 分钟
B. Tavas and SaDDas time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn’t stop doing that. That’s why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas’ headphones and told him: “If you solve the following problem, I’ll return it to you.”

codeforces 534 A. Exam

·2 分钟
A. Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.

codeforces 479D. Long Jumps

·2 分钟
http://codeforces.com/problemset/problem/479/D 题意是说有一把尺子,本身有一些刻度,然后需要测量x和y,问最少需要添加多少个刻度,如果需要,这些刻度分别添加在什么位置。

codeforces 525 B. Pasha and String

·1 分钟
http://codeforces.com/problemset/problem/525/B 1题意是说一个字符串,进行m次颠倒变换(从a[i]位置到a[l-i+1]位置),问得到的字符串。容易发现,对于越在里边(对称,也就是越靠近中间位置)的字符,调换的次数越多。我们可以把a[i]从小到大排序。然后经过分析发现,把两个相邻的a[i]分为一组,做处理,如果m为奇数,最后还剩下a[m]没有被分组,要单独处理a[m]细节上要注意st数组是从st[0]开始的...好吧的确不方便,适牛也说我了。。数组下标以后还是从0开始吧。。。主要是受高中OI用的pascal的影响。。。那个数组下标随便啊。代码: 2 3 4 5 6 /* *********************************************** 7 Author :111qqz 8 Created Time :2016年02月22日 星期一 23时39分51秒 9 File Name :code/cf/problem/525B.cpp 10 ************************************************ */ 11 12 #include <iostream> 13 #include <algorithm> 14 #include <cstring> 15 #include <cmath> 16 #include <cstdio> 17 18 using namespace std; 19 20 int m,k,len; 21 const int N=2E5+7; 22 int a[N]; 23 char st[N]; 24 25 int main() 26 { 27 cin>>st; 28 scanf("%d",&m); 29 for ( int i = 1 ; i <= m ; i++ ) 30 scanf("%d",&a[i]); 31 sort(a+1,a+m+1); 32 k = 1; 33 len = strlen(st); 34 while (k<=m) 35 { 36 for ( int j = a[k] ; j <= a[k+1]-1 ; j++) 37 swap(st[j-1],st[len-j]); 38 k = k + 2; 39 } 40 if ( m %2==1 ) 41 for ( int i = a[m]; i <= len/2 ; i++ ) 42 swap(st[i-1],st[len-i]); 43 cout<<st<<endl; 44 return 0; 45 }