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.
The first line contains a single integer x (1 ≤ x ≤ 1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
27
22
4545
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;
}
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.
The first line contains three integers n, x0 и 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 xi, yi ( - 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.
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
4 0 0 1 1 2 2 2 0 -1 -1
2
2 1 2 1 1 1 0
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;
}
- - 在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;
}