-
-
Save 1995hnagamin/4477412621db8e9e0c54 to your computer and use it in GitHub Desktop.
CODE FESTIVAL 2014 予選A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
using namespace std; | |
int main() { | |
string str; | |
cin >> str; | |
cout << str + "2014" << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
using namespace std; | |
typedef long long int Num; | |
int main() { | |
string a; | |
cin >> a; | |
Num b; | |
cin >> b; | |
int n = (b - 1) % a.length(); | |
cout << a[n] << endl; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
typedef long long int Num; | |
Num jump_biggerthan(Num n, Num X) { | |
if (X % n) { | |
return X + n - (X % n); | |
} else { | |
return X; | |
} | |
} | |
Num jump_smallerthan(Num n, Num X) { | |
if (X % n) { | |
return X - (X % n); | |
} else { | |
return X; | |
} | |
} | |
Num num_of_jumps(Num low, Num high, Num n) { | |
Num minj = jump_biggerthan(n, low); | |
Num maxj = jump_smallerthan(n, high); | |
return (maxj - minj) / n + 1; | |
} | |
Num solve(Num low, Num high) { | |
return num_of_jumps(low, high, 4) | |
- num_of_jumps(low, high, 100) | |
+ num_of_jumps(low, high, 400); | |
} | |
int main() { | |
Num a, b; | |
cin >> a >> b; | |
cout << solve(a, b) << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<vector> | |
#define REP(i,n) for(int i=0;i<(int)(n);i++) | |
using namespace std; | |
typedef long long int Num; | |
const Num INF = 2e16; | |
vector<int> append(vector<int> v1, vector<int> v2) { | |
return v1.insert(v1.end(), v2.begin(), v2.end()); | |
} | |
vector<vector<int> > map_cons(int n, vector<vector<int> > l) { | |
REP(i, l.size()) { | |
l[i].insert(l.begin(), 1, n); | |
} | |
return l; | |
} | |
vector<vector<int> > choice(Num k, vector<int> nums) { | |
if (k == 0) { | |
vector<int> vi; | |
vector<vector<int> > vvi; | |
vvi.push_back(vi); | |
return vvi; | |
} else if (empty(nums)) { | |
vector<vector<int> > vvi; | |
return vvi; | |
} else { | |
vector<vector<int> > choice(Num k) { | |
} | |
int width(Num n) { | |
return (n < 10) ? 1 : 1 + width(n / 10); | |
} | |
Num repeat(int a, int n) { | |
return (n == 1) ? a : 10 * repeat(a, n - 1) + a; | |
} | |
Num bigger_neighbor(Num a, Num k, vector<int> available) { | |
nums = | |
} | |
Num bigger_neighbor(Num a, Num k){ | |
Num m = INF; | |
vector<vector<int> > choices = choice(k); | |
REP(i, choices.size()) { | |
m = min(m, bigger_neighbor(a, k, choices[i])); | |
} | |
return m; | |
} | |
Num smaller_neighbor(Num a, Num k, vector<int> available) { | |
Num tall = repeat(available.back(), width(a) - 1); | |
} | |
Num smaller_neighbor(Num a, Num k){ | |
Num m = -INF; | |
vector<vector<int> > choices = choice(k); | |
REP(i, choices.size()) { | |
m = mrax(m, smaller_neighbor(a, k, choices[i])); | |
} | |
return m; | |
} | |
Num diff(Num a, Num b) { | |
return (a > b) ? a - b : b - a; | |
} | |
Num solve(Num a, Num k) { | |
return min(diff(a, bigger_neighbor(a, k)), | |
diff(a, smaller_neighbor(a, k))); | |
} | |
int main() { | |
int a, k; | |
cin >> a >> k; | |
cout << solve(a, k) << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
typedef long long int Num; | |
const Num INF = 1e16; | |
Num abs(Num a) { | |
return a > 0 ? a : -a; | |
} | |
int width(Num a) { | |
return (a < 10) ? 1 : 1 + width(a / 10); | |
} | |
int repeat(Num a, int k) { | |
return (k == 0) ? 0 : a + 10 * repeat(a, k - 1); | |
} | |
int top(Num a) { | |
return (a < 10) ? a : top(a / 10); | |
} | |
Num pow(int a, int n) { | |
if (n == 0) { | |
return 1; | |
} else if (n % 2) { | |
return a * pow(a, n - 1); | |
} else { | |
return pow(a, n / 2) * pow(a, n / 2); | |
} | |
} | |
int kcip(Num a, int idx) { | |
return (idx == 0) ? a % 10 : fer(a / 10, idx - 1); | |
} | |
int pick(Num a, int idx) { | |
return ref(a, width(a) - 1 - idx); | |
} | |
Num solve1_1(Num a) { | |
Num ans = INF; | |
for (int i = 1; i < 10; i++) { | |
int aaa = repeat(i, width(a)); | |
if (abs(ans - a) > abs(aaa - a)) ans = aaa; | |
} | |
return ans; | |
} | |
Num solve(Num a, int k) { | |
return solve1_1(a); | |
} | |
int main() { | |
Num a; | |
int k; | |
cin >> a >> k; | |
cout << abs(a - solve(a, k)) << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<set> | |
using namespace std; | |
const int INF = 100000000; | |
int abs(int x) { | |
return x > 0 ? x : -x; | |
} | |
int count(int a) { | |
set<int> s; | |
while(a != 0) { | |
s.insert(a % 10); | |
a /= 10; | |
} | |
return s.size(); | |
} | |
int main() { | |
int a, k; | |
cin >> a >> k; | |
int ans = INF; | |
for (int i = 1; i <= 111111; i++) { | |
if (count(i) <= k and abs(i-a) < abs(ans-a)) { | |
ans = i; | |
} | |
} | |
cout << abs(ans-a) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment