跳过正文
  1. Posts/

codeforces 18 C. Stripe

·1 分钟

http://codeforces.com/contest/18/problem/C 题意:将一个序列分成两个非空的部分,保证和相等,问有多少种方法。 思路:做过一个三部分的。。。两部分直接一个前缀和就好了把。。。有一个需要注意的是。。判断负数是否是奇数的时候需要加个绝对值。。。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2015年12月29日 星期二 16时09分06秒
 4File Name :code/cf/problem/18C.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E5+7;
34int n;
35int total;
36int sum[N];
37int main()
38{
39	#ifndef  ONLINE_JUDGE
40//	freopen("code/in.txt","r",stdin);
41  #endif
42
43	cin>>n;
44	sum[0] = 0 ;
45	for ( int i = 1 ; i <= n ; i++)
46	{
47	    int x;
48	    cin>>x;
49	    sum[i] = sum[i-1]+x;
50	}
51
52	total = sum[n];
53	if (abs(total)%2==1)
54	{
55	    puts("0");
56	    return 0;
57	}
58	total /=2;
59	int ans = 0 ;
60	for ( int i = 1 ; i <= n-1 ; i++)
61	{
62	    if (sum[i]==total) ans++;
63	}
64	cout<<ans<<endl;
65
66  #ifndef ONLINE_JUDGE
67  fclose(stdin);
68  #endif
69    return 0;
70}

相关文章

codeforces #336 div 2 B. Hamming Distance Sum

·1 分钟
http://codeforces.com/contest/608/problem/B 题意:给定两个字符串a,b,问b中的每个连续的长度为a的子串与a的哈密顿距离的和是多少。哈密顿距离是对应位置的字符的差的绝对值的和。由于是01串,也就是字符不同的位置数。 思路:类似前缀和。0和1分别搞。注意开long long

codeforces 12 C. Fruits

·1 分钟
http://codeforces.com/contest/12/problem/C 题意:有n个价格价格,m个要买的东西(可能有相同的种类,设为k种),把n个标签中拿出k个给个贴上。。。问最大价钱和最少价钱分别是多少。 思路:贪心。不过要按照map的value排序。。然后发现其实不用排序。。因为map的key值其实不影响。

codeforces 16 C. Monitor

·1 分钟
http://codeforces.com/contest/16/problem/C 题意:给定长宽a,b和分辨率x:y,注意分辨率x:y未必是最简比。问将现有的size裁剪成比例为x:y,使得面积最大的长宽是多少。 思路:可以通过找 x,y能扩大的倍数为k,找到一个最大的k使得k*x<=a&&k;*y<=b。可以二分搞,但其实也可以不用。能扩大的最大的倍数其实就是 min(a/x,b/y). ps:收获了gcd更简单的一种写法。 直接 return b?gcd(b,a%b):a;

codeforces 612 C. Replace To Make Regular Bracket Sequence

·1 分钟
http://codeforces.com/contest/612/problem/C 题意:其实就是栈的基本操作。。水题。 1/* *********************************************** 2Author :111qqz 3Created Time :2015年12月25日 星期五 22时58分50秒 4File Name :code/cf/edu4/C.cpp 5************************************************ */ 6 7#include <cstdio> 8#include <cstring> 9#include <iostream> 10#include <algorithm> 11#include <vector> 12#include <queue> 13#include <set> 14#include <map> 15#include <string> 16#include <cmath> 17#include <cstdlib> 18#include <ctime> 19#define fst first 20#define sec second 21#define lson l,m,rt<<1 22#define rson m+1,r,rt<<1|1 23#define ms(a,x) memset(a,x,sizeof(a)) 24typedef long long LL; 25#define pi pair < int ,int > 26#define MP make_pair 27 28using namespace std; 29const double eps = 1E-8; 30const int dx4[4]={1,0,0,-1}; 31const int dy4[4]={0,-1,1,0}; 32const int inf = 0x3f3f3f3f; 33const int N=1E6+7; 34int len; 35char st[N]; 36int cost = 0 ; 37 38char a[N]; 39int n ; 40 41 42int which(char ch) 43{ 44 if (ch=='<'||ch=='{'||ch=='('||ch=='[') return 1; 45 return 2; 46} 47int kin(char ch) 48{ 49 if (ch=='{'||ch=='}') return 1; 50 if (ch=='['||ch==']') return 2; 51 if (ch=='<'||ch=='>') return 3; 52 if (ch=='('||ch==')') return 4; 53} 54bool ok(char x,char y) 55{ 56 int res = 0 ; 57 if(x=='<'||x=='{'||x=='['||x=='(') res++; 58 if (y=='>'||y=='}'||y==']'||y==')') res++; 59 if (res==2) 60 { 61 if (kin(x)!=kin(y)) cost++; 62// cout<<"x:"<<x<<" y:"<<y<<endl; 63 return true; 64 } 65 return false; 66} 67 68int main() 69{ 70 #ifndef ONLINE_JUDGE 71 freopen("code/in.txt","r",stdin); 72 #endif 73 cin>>st; 74 len = strlen(st); 75 int head = -1; 76 int ans = 0 ; 77 78 for ( int i = 0 ; i < len ; i++) 79 { 80 if (head==-1) 81 { 82 head++; 83 a[head] = st[i]; 84 if (which(st[i])==2) 85 { 86 puts("Impossible"); 87 return 0; 88 } 89 90 continue; 91 } 92 if (ok(a[head],st[i])) 93 { 94 head--; 95 } 96 else 97 { 98 head++; 99 a[head] = st[i]; 100 } 101 102// cout<<"head:"<<head<<endl; 103 } 104// cout<<"head:"<<head<<endl; 105 if (head!=-1) 106 { 107 puts("Impossible"); 108 } 109 else 110 { 111 cout<<cost<<endl; 112 } 113 114 #ifndef ONLINE_JUDGE 115 fclose(stdin); 116 #endif 117 return 0; 118}