↓ 跳过正文
  1. Posts/

codeforces 1 B. Spreadsheets

·632 字·2 分钟

http://codeforces.com/problemset/problem/1/B 题意:给出了两种表格的表示方法。要求互相转化。 思路:直接模拟即可。注意和一般的进制转化不同的是,26进制对应的是1到26而不是0到25,所以要记得处理下借位。

代码实现
  1/* ***********************************************
  2Author :111qqz
  3Created Time :2015年12月13日 星期日 19时46分09秒
  4File Name :code/cf/problem/1B.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;
 33
 34char st[100];
 35int a26[100];
 36int a10[100];
 37
 38void pre()
 39{
 40    a26[0]=1;
 41    for ( int i = 1 ;i<=5; i++)
 42    {
 43	a26[i] = a26[i-1]*26;
 44//	cout<<"i:"<<i<<" "<<a26[i]<<endl;
 45    }
 46    a10[0] = 1;
 47    for ( int i = 1 ; i<=7 ; i++)
 48    {
 49	a10[i] = a10[i-1]*10;
 50    }
 51}
 52void solve()
 53{
 54    cin>>st;
 55    int len = strlen(st);
 56    int p1=-1,p2=-1;
 57    for ( int i = 0 ; i < len ; i++)
 58    {
 59	char ch = st[i];
 60	if (ch>='A'&&ch<='Z')
 61	{
 62	    if (p1==-1)
 63	    {
 64		p1 = i ;
 65	    }
 66	    else
 67	    {
 68		p2 = i;
 69		break;
 70	    }
 71	}
 72    }
 73    if (p2-p1==1||p2==-1)
 74    {
 75	int dig = 0 ;
 76	int alp = 0;
 77	int sum = 0 ;
 78	int sum2 = 0 ;
 79	for ( int i = len -1 ; i>= 0 ; i--)
 80	{
 81	    char ch = st[i];
 82	    if (!isdigit(ch))
 83	    {
 84		sum += (ch-'A'+1)*a26[alp];
 85		alp++;
 86	    }
 87	    else
 88	    {
 89		sum2+= (ch-'0')*a10[dig];
 90		dig++;
 91	    }
 92	}
 93	printf("R%d\n",sum2,sum);
 94    }
 95    else
 96    {
 97	int dig1 = 0 ;
 98	int dig2 = 0;
 99	int sum1 = 0 ;
100	int sum2 = 0 ;
101	int p = 1;
102	for ( int i = len-1 ; i>= 0 ; i-- )
103	{
104	    char ch = st[i];
105	    if (isdigit(ch))
106	    {
107	//	cout<<"ch:"<<ch<<endl;
108		if (p)
109		{
110		    sum1+=(ch-'0')*a10[dig1];
111		  //  cout<<"sum1:"<<sum1<<endl;
112		    dig1++;
113		}
114		else
115		{
116		    sum2+=(ch-'0')*a10[dig2];
117		    dig2++;
118		}
119
120
121	    }
122	    else
123	    {
124		p = 0 ;
125	    }
126	}
127//	cout<<"sum1:"<<sum1<<" sum2:"<<sum2<<endl;
128	    int cnt = 0 ;
129	    int b[50];
130	    while(sum1)
131	    {
132		cnt++;
133		b[cnt] = sum1;
134		sum1/=26;
135//		cout<<"sum1::::"<<sum1<<endl;
136	    }
137//	    cout<<"cnt:"<<cnt<<endl;
138	    for ( int i = 1 ; i <= cnt -1 ; i ++)
139	    {
140		if (b[i]<=0)
141		{
142		    b[i]+=26;
143		    b[i+1]--;
144		}
145	    }
146	    while (b[cnt]==0) cnt--;
147
148	    for ( int i = cnt ; i >=1 ; i--)
149	    {
150
151	//	cout<<"b[i]:"<<b[i]<<endl;
152		cout<<char(b[i]+'A'-1);
153	    }
154	    cout<<sum2<<endl;
155
156
157
158
159    }
160
161
162}
163int main()
164{
165	#ifndef  ONLINE_JUDGE
166	freopen("code/in.txt","r",stdin);
167  #endif
168
169	pre();
170	int T;
171	cin>>T;
172	while (T--)
173	{
174	    solve();
175	}
176
177  #ifndef ONLINE_JUDGE
178  fclose(stdin);
179  #endif
180    return 0;
181}

相关文章

codeforces 158 B. Taxi

·419 字·1 分钟
http://codeforces.com/problemset/problem/158/B 题意:n组人,每组有si个(1<=si<=4),每辆车能装4个人。问最少需要多少辆车装下所有人并且保证同一组的人在一辆车里。 思路:统计人数分别为1,2,3,4的人数。对于4的直接加到答案。贪心的思路是:优先用人数少的去填人数多的。

hdoj 5479 || bestcoder #57 div 2 A Scaena Felix(模拟)

·257 字·1 分钟
模拟. 直接搞… 并不明白坑在哪里... 排在我前面被hack了100多人… 代码实现 1/************************************************************************* 2 > File Name: code/bc/#57/1001.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年09月26日 星期六 19时04分34秒 6 ************************************************************************/ 7 8#include<iostream> 9#include<iomanip> 10#include<cstdio> 11#include<algorithm> 12#include<cmath> 13#include<cstring> 14#include<string> 15#include<map> 16#include<set> 17#include<queue> 18#include<vector> 19#include<stack> 20#include<cctype> 21#define y1 hust111qqz 22#define yn hez111qqz 23#define j1 cute111qqz 24#define ms(a,x) memset(a,x,sizeof(a)) 25#define lr dying111qqz 26using namespace std; 27#define For(i, n) for (int i=0;i<int(n);++i) 28typedef long long LL; 29typedef double DB; 30const int inf = 0x3f3f3f3f; 31const int N=1E3+7; 32char str[N]; 33int len; 34int main() 35{ 36 #ifndef ONLINE_JUDGE 37 freopen("in.txt","r",stdin); 38 #endif 39 int T; 40 cin>>T; 41 while (T--) 42 { 43 scanf("%s",str); 44 len = strlen(str); 45 int cnt = 0; 46 int ans = 0 ; 47 for ( int i = 0 ; i < len ; i++) 48 { 49 if (str[i]=='(') 50 { 51 cnt++; 52 } 53 else 54 { 55 cnt--; 56 if (cnt>=0) 57 { 58 ans++; 59 } 60 if (cnt<0) 61 cnt = 0 ; 62 } 63 } 64 printf("%d\n",ans); 65 } 66 67 #ifndef ONLINE_JUDGE 68 fclose(stdin); 69 #endif 70 return 0; 71}

codeforces # 317 div 2 B. Order Book(模拟)

·991 字·2 分钟
B. Order Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price p__i, direction d__i – buy or sell, and integer q__i. This means that the participant is ready to buy or sell q__i stocks at price p__i for one stock. A value q__i is also known as a volume of an order.

bc #52 div 2 A ||hdoj5417 Victor and Machine (模拟)

·262 字·1 分钟
傻逼模拟题 我做了半小时…. sssssad 代码实现 1/************************************************************************* 2 > File Name: code/bc/#52/1001.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年08月22日 星期六 18时51分44秒 6 ************************************************************************/ 7#include<iostream> 8#include<iomanip> 9#include<cstdio> 10#include<algorithm> 11#include<cmath> 12#include<cstring> 13#include<string> 14#include<map> 15#include<set> 16#include<queue> 17#include<vector> 18#include<stack> 19#include<cctype> 20#define y1 hust111qqz 21#define yn hez111qqz 22#define j1 cute111qqz 23#define ms(a,x) memset(a,x,sizeof(a)) 24#define lr dying111qqz 25using namespace std; 26#define For(i, n) for (int i=0;i<int(n);++i) 27typedef long long LL; 28typedef double DB; 29const int inf = 0x3f3f3f3f; 30const int N=1E6+7; 31int main() 32{ 33 #ifndef ONLINE_JUDGE 34 freopen("in.txt","r",stdin); 35 #endif 36 int x,y,w,n; 37 while (scanf("%d%d%d%d",&x,&y,&w,&n)!=EOF){ 38 int num = 1; 39 int cnt; 40 int q; 41 bool on = true; 42 bool flag = false; 43 int t = 0; 44 while (t<N&&!flag){ 45 if (num==n) { 46 cout<<t<<endl; 47 flag = true; 48 break; 49 } 50 cnt = t+x; 51 q = 0; 52 while (t<cnt){ 53 q++; 54 t++; 55 if (q%w==0){ 56// cout<<"aaat:"<<t<<endl; 57 num++; 58 } 59 if (num == n){ 60 cout<<t<<endl; 61 flag = true; 62 break; 63 } 64 } 65 on = false; 66 t = t + y; 67 on = true; 68 num++; 69 if (num==n){ 70 cout<<t<<endl; 71 flag = true; 72 } 73 } 74 } 75 #ifndef ONLINE_JUDGE 76 fclose(stdin); 77 #endif 78 return 0; 79}