hh:mm:ss で与えられるため秒に統一する。
hh ->*60*60
mm->*60
ss
その時間に出発した電車、到着した電車の数をカウントする。
その時間にどれだけの電車が走っているかをカウントし、その最大値が答えになる。
/*********************************
* 2012/0714 *
* AOJ_Volume20_2013 *
* Osaki *
* crane *
**********************************/
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX_N 24*60*60
int field[MAX_N];
int main(){
int n;
while(cin >> n, n){
for(int i=0; i<MAX_N; i++)
field[i] = 0;
int h1,m1,s1,h2,m2,s2;
for(int i=0; i<n; i++){
scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
int t1 = (h1 * 3600) + (m1 * 60) + s1;//秒に統一
int t2 = (h2 * 3600) + (m2 * 60) + s2;
field[t1]++; //その時間に出発した電車をカウント
field[t2]--; //その時間に到着した電車をカウント
}
int m_count=0, count=0;
for(int i=0; i<MAX_N; i++){//その時間に走っている車両数の最大値が答えになる。
count += field[i];
m_count = max(m_count, count);
}
cout << m_count << endl;
}
return 0;
}
Amazon
2012年7月14日土曜日
2012年7月7日土曜日
AOJ Volume20 2001: Amida the city of Miracle
/***************************
* 2012/07/07 *
* AOJ_Volume20_2001 *
* Amida_the_city_of_Miracle*
* crane *
****************************/
#include<iostream>
using namespace std;
#define MAX_H 1001
#define MAX_N 101
int field[MAX_H][MAX_N];
int main(){
int n,m,a;
while(cin >> n >> m >> a, (n||m||a)){//n:縦線、m:横線、a:調べる縦線
for(int i=1; i<MAX_H; i++){
for(int j=1; j<=n; j++){
field[i][j] = j;
}
}
int h, p, q; //h:横線の高さ p,q:つながっている横線
for(int i=0; i<m; i++){
cin >> h >> p >> q;
field[h][p] = q;
field[h][q] = p;
}
int res= a;
for(int i=MAX_H-1; 0<i; i--){
res = field[i][res];
}
cout << res << endl;
}
return 0;
}
* 2012/07/07 *
* AOJ_Volume20_2001 *
* Amida_the_city_of_Miracle*
* crane *
****************************/
#include<iostream>
using namespace std;
#define MAX_H 1001
#define MAX_N 101
int field[MAX_H][MAX_N];
int main(){
int n,m,a;
while(cin >> n >> m >> a, (n||m||a)){//n:縦線、m:横線、a:調べる縦線
for(int i=1; i<MAX_H; i++){
for(int j=1; j<=n; j++){
field[i][j] = j;
}
}
int h, p, q; //h:横線の高さ p,q:つながっている横線
for(int i=0; i<m; i++){
cin >> h >> p >> q;
field[h][p] = q;
field[h][q] = p;
}
int res= a;
for(int i=MAX_H-1; 0<i; i--){
res = field[i][res];
}
cout << res << endl;
}
return 0;
}
AOJ Volume20 2000: Misterious Games
/*************************
* 2012/07/07 *
* AOJ_Volume20_2000 *
* Misterious_Gems *
* crane *
**************************/
#include<iostream>
using namespace std;
#define FIELD 21
bool field[FIELD][FIELD];
int main(){
int n; //宝石の個数
while(cin >> n, n){
for(int i=0; i<FIELD; i++)
for(int j=0; j<FIELD; j++)
field[i][j] = false;
/*--宝石の位置--*/
int xi, yi;
for(int i=0; i<n; i++){
cin >> xi >> yi;
field[yi][xi] = true;
}
int m; //命令の個数
cin >> m;
char dj;
int lj;
int x = 10, y = 10; //ロボット降下位置
for(int i=0; i<m; i++){
cin >> dj >> lj; //命令取得
while(lj--){
switch (dj){
case 'N':
y++;
break;
case 'E':
x++;
break;
case 'S':
y--;
break;
case 'W':
x--;
break;
}
if(field[y][x]){
n--;
field[y][x] = false;
}
}
}
if(n == 0) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
2012年7月4日水曜日
AOJ Volume20 2006: Keitai Message
/****************************
* 2012/06/23 *
* AOJ_2006 *
* keitai message *
* crane *
*****************************/
#include<iostream>
#include<string>
using namespace std;
char m[][6] = {
{},
{5, '.', ',', '!', '?', ' '}, // 1
{3, 'a', 'b', 'c'}, // 2
{3, 'd', 'e', 'f'}, // 3
{3, 'g', 'h', 'i'}, // 4
{3, 'j', 'k', 'l'}, // 5
{3, 'm', 'n', 'o'}, // 6
{4, 'p', 'q', 'r', 's'}, // 7
{3, 't', 'u', 'v'}, // 8
{4, 'w', 'x', 'y', 'z'}, // 9
};
int main(){
int n; //テストケース数
cin >> n;
while(n--){
string str;
cin >> str;
int s = 0, cnt = -1;
for(int i=0; i<str.size(); i++){
int d = str[i] - '0';
if(d==0){
if(s!=0) cout << m[s][(cnt % m[s][0]) + 1];
s = 0; cnt = -1;
}else{
s = d;
cnt++;
}
}
cout << endl;
}
return 0;
}
* 2012/06/23 *
* AOJ_2006 *
* keitai message *
* crane *
*****************************/
#include<iostream>
#include<string>
using namespace std;
char m[][6] = {
{},
{5, '.', ',', '!', '?', ' '}, // 1
{3, 'a', 'b', 'c'}, // 2
{3, 'd', 'e', 'f'}, // 3
{3, 'g', 'h', 'i'}, // 4
{3, 'j', 'k', 'l'}, // 5
{3, 'm', 'n', 'o'}, // 6
{4, 'p', 'q', 'r', 's'}, // 7
{3, 't', 'u', 'v'}, // 8
{4, 'w', 'x', 'y', 'z'}, // 9
};
int main(){
int n; //テストケース数
cin >> n;
while(n--){
string str;
cin >> str;
int s = 0, cnt = -1;
for(int i=0; i<str.size(); i++){
int d = str[i] - '0';
if(d==0){
if(s!=0) cout << m[s][(cnt % m[s][0]) + 1];
s = 0; cnt = -1;
}else{
s = d;
cnt++;
}
}
cout << endl;
}
return 0;
}
登録:
投稿 (Atom)