Codeforces #291 (div2)

A. Chewbaсca and Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t.

Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.

Input

The first line contains a single integer x (1 ≤ x ≤ 1018) — the number that Luke Skywalker gave to Chewbacca.

Output

Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.

Sample test(s)
input
27
output
22
input
4545
output
4444
= = 两个坑点 一个是位数不变 一个是正数 记得读题仔细 - -

AC代码如下:

//
//  A. Chewba§ãca and Number
//
//  Created by TaoSama on 2015-02-15
//  Copyright (c) 2014 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

char a[20];

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	while(cin >> a) {
		int n = strlen(a);
		if(a[0] >= '5' && a[0] <= '8') a[0] = '0' + '9' - a[0];
		for(int i = 1; i < n; ++i)
			if(a[i] >= '5') a[i] = '0' + '9' - a[i];
		cout << a << endl;
	}
	return 0;
}


B. Han Solo and Lazer Gun
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.

Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).

Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.

The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.

Input

The first line contains three integers nx0 и y0 (1 ≤ n ≤ 1000 - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun.

Next n lines contain two integers each xiyi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.

Output

Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.

Sample test(s)
input
4 0 0
1 1
2 2
2 0
-1 -1
output
2
input
2 1 2
1 1
1 0
output
1

用叉积判断是否在一条直线上 - - 开vis标记一下就好了

AC代码如下:

//
//  B. Han Solo and Lazer Gun
//
//  Created by TaoSama on 2015-02-15
//  Copyright (c) 2014 TaoSama. All rights reserved.
//

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

int x0, y0, n, x[1005], y[1005];
bool vis[1005];

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	while(cin >> n >> x0 >> y0) {
		memset(vis, 0, sizeof vis);
		for(int i = 1; i <= n; ++i) cin >> x[i] >> y[i];
		int ans = 0;
		for(int i = 1; i <= n; ++i) {
			if(!vis[i]) {
				++ans; vis[i] = true;
				for(int j = 1; j <= n; ++j) {
					if(!vis[j]) {
						if((x[j] - x0) * (y[i] - y0) == (x[i] - x0) * (y[j] - y0))
							vis[j] = true;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


C. Watto and Mechanism
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mechanism contains string t that consists of the same number of characters as s and differs from s in exactly one position".

Watto has already compiled the mechanism, all that's left is to write a program for it and check it on the data consisting of n initial lines and m queries. He decided to entrust this job to you.

Input

The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·1050 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively.

Next follow n non-empty strings that are uploaded to the memory of the mechanism.

Next follow m non-empty strings that are the queries to the mechanism.

The total length of lines in the input doesn't exceed 6·105. Each line consists only of letters 'a''b''c'.

Output

For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).

Sample test(s)
input
2 3
aaaaa
acacaca
aabaa
ccacacc
caaac
output
YES
NO
NO


- - 在t不是很大的时候用set维护一下字典 这样会很快 在t很大的时候来让我看下大神的姿势分析

所以就不会T了 - - 如果全部用set维护的话 会MLE - - 感觉这种姿势好适合我这种不会hash的人

AC代码如下:

//
//  C. Watto and Mechanism
//
//  Created by TaoSama on 2015-02-15
//  Copyright (c) 2014 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 3e5 + 10;

int n, m;
string t, dict[N];
set<string> s;

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	cin >> n >> m;

	for(int i = 1; i <= n; ++i) {
		cin >> dict[i];
		s.insert(dict[i]);
	}
	for(int i = 1; i <= m; ++i) {
		cin >> t; bool ok = false;
		if(t.size() <= 100) {
			for(int j = 0; j < t.size(); ++j) {
				char ch = t[j];
				for(int k = 0; k < 3; ++k) {
					if(t[j] == 'a' + k) continue;
					t[j] = 'a' + k;
					if(s.count(t)) ok = true;
					t[j] = ch;
					if(ok) break;
				}
				if(ok) break;
			}
			if(ok) cout << "YES" << endl;
			else   cout << "NO" << endl;
			continue;
		}
		for(int j = 1; j <= n; ++j) {
			if(dict[j].size() != t.size()) continue;
			int diff = 0;
			for(int k = 0; k < t.size(); ++k)
				if(dict[j][k] != t[k]) {
					++diff;
					if(diff > 1) break;
				}
			if(diff == 1) {ok = true; break;}
		}
		if(ok) cout << "YES" << endl;
		else   cout << "NO" << endl;
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值