↓ 跳过正文
  1. Posts/

codeforces 612 C. Replace To Make Regular Bracket Sequence

·358 字·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}

相关文章

codeforces 612 B. HDD is Outdated Technology

·229 字·1 分钟
http://codeforces.com/contest/612/problem/B 水。 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2015年12月25日 星期五 22时58分38秒 4File Name :code/cf/edu4/B.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=2E5+7; 34int n; 35struct node 36{ 37 int val; 38 int id; 39 40 bool operator <(node b)const 41 { 42 return val<b.val; 43 } 44}q[N]; 45int main() 46{ 47 #ifndef ONLINE_JUDGE 48 freopen("code/in.txt","r",stdin); 49 #endif 50 cin>>n; 51 for ( int i = 1 ; i <= n ; i++ ) 52 { 53 scanf("%d",&q[i].val); 54 q[i].id = i; 55 } 56 sort(q+1,q+n+1); 57 LL ans = 0 ; 58 q[0].id = 0 ; 59 for ( int i = 1 ; i <= n-1 ; i++) 60 { 61 ans += LL (abs(q[i+1].id-q[i].id)); 62 } 63 cout<<ans<<endl; 64 65 #ifndef ONLINE_JUDGE 66 fclose(stdin); 67 #endif 68 return 0; 69}

codeforces 612 A. The Text Splitting

·319 字·1 分钟
http://codeforces.com/contest/612/problem/A 水题…直接枚举就好。 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2015年12月25日 星期五 22时58分26秒 4File Name :code/cf/edu4/A.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=105; 34int n,p,q; 35char st[N]; 36bool v[10005]; 37int main() 38{ 39 #ifndef ONLINE_JUDGE 40 freopen("code/in.txt","r",stdin); 41 #endif 42 cin>>n>>p>>q; 43 cin>>st; 44 ms(v,false); 45 int b,c; 46 for ( int i = 0 ; i*p<=105 ; i++ ) 47 { 48 for ( int j = 0 ; j*q <= 105 ; j++) 49 { 50 v[i*p+j*q] = true; 51 if (i*p+j*q==n) 52 { 53 b = i; 54 c = j; 55 } 56 } 57 } 58// cout<<"b:"<<b<<endl; 59// cout<<"c:"<<c<<endl; 60 if (!v[n]) 61 { 62 puts("-1"); 63 } 64 else 65 { 66 int cnt = 0 ; 67 printf("%d\n",b+c); 68 for ( int i = 1 ; i <= b ; i++) 69 { 70 for ( int i = 0 ; i < p ; i++) 71 printf("%c",st[cnt]),cnt++; 72 printf("\n"); 73 } 74 for ( int i =1 ; i <= c ; i++) 75 { 76 for ( int i = 0 ; i < q ; i++) 77 printf("%c",st[cnt]),cnt++; 78 printf("\n"); 79 } 80 } 81 82 83 84 #ifndef ONLINE_JUDGE 85 fclose(stdin); 86 #endif 87 return 0; 88}

uva 6692 Lucky Number

·395 字·1 分钟
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4704 题目大意是说,定义一个数的lucky number是距离i最远的j且满足(a[i]<a[j] i<j)。

codeforces 589 I - Lottery(水)

·520 字·2 分钟
I - Lottery **Time Limit:**2000MS **Memory Limit:**524288KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589I Description Today Berland holds a lottery with a prize – a huge sum of money! There are k persons, who attend the lottery. Each of them will receive a unique integer from 1 to k.

codeforces #326 div 2 A. Duff and Meat(水)

·503 字·2 分钟
A. Duff and Meat time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly a__i kilograms of meat.