题意:给你一个序列,问你选定一个K(1 - N-1)值,改变给定序列使得让Ai - Ak  < 0  ,Ak+1 - An  >0 成立,问你最少改多少次

解题思路:这么水的C。。。正反dp找正负就行

解题代码:

 1 // File Name: 234c.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年08月03日 星期日 16时16分35秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25 
26 using namespace std;
27 int a[100005];
28 int za[100005];
29 int fa[100005];
30 int ans = 1e9; 
31 int main(){
32      freopen("input.txt","r",stdin);
33      freopen("output.txt","w",stdout);
34 
35      int n ;
36      scanf("%d",&n);
37      memset(za,0,sizeof(za));
38      memset(fa,0,sizeof(fa));
39      for(int i = 1;i <= n;i ++)
40      {
41         scanf("%d",&a[i]);
42         if(a[i] >= 0)
43         {
44            za[i] = za[i-1] + 1;   
45         }else{
46            za[i] = za[i-1];
47         }
48      }
49      for(int i = n;i >= 2; i --)
50      {
51         if(a[i] <= 0 )
52         {
53            fa[i] = fa[i+1] +1;
54         }else{
55            fa[i] = fa[i+1];
56         }
57         if(fa[i] + za[i-1] < ans)
58             ans = fa[i] + za[i-1];
59      }
60      printf("%d\n",ans);
61 return 0;
62 }
View Code

 

posted on 2014-08-03 16:29  dark_dream  阅读(233)  评论(0编辑  收藏  举报