Skip to content

Instantly share code, notes, and snippets.

@akahana-1
Created December 22, 2014 22:21
Show Gist options
  • Save akahana-1/9d5cd8859e128a129c29 to your computer and use it in GitHub Desktop.
Save akahana-1/9d5cd8859e128a129c29 to your computer and use it in GitHub Desktop.
CODE THANKS FESTIVAL B日程
#include <iostream>
#include <algorithm>
using namespace std;
int calc(int a, int b, int opr){
switch (opr){
case 1:
return a + b;
case 2:
return a - b;
case 3:
return a * b;
case 4:
return a / b;
default:
return 0;
}
return 0;
}
int main(){
int a, b, c, ans = 0;
cin >> a >> b >> c;
for (int i = 0; i < 4; ++i){
for (int j = 0; j < 4; ++j){
ans = max(ans, calc(calc(a, b, i), c, j));
}
}
cout << ans << endl;
return 0;
}
#include <iostream>
using namespace std;
int main(){
int n, c = 0;
int res[2][100];
cin >> n;
for (int i = 0; i < 2; ++i){
for (int j = 0; j < n; ++j){
cin >> res[i][j];
}
}
for (int i = 0; i < n; ++i){
if (res[0][i] / 2 < res[1][i]) ++c;
}
cout << c << endl;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1000, T = 1000;
int main(){
int n, t, a, res = 0;
int times[T + 1];
fill(times, times + (T + 1), 0);
cin >> n >> t;
for (int i = 0; i < n; ++i){
cin >> a;
for (int j = a; j < t + 1; j += a){
times[j]++;
}
}
for (int i = 0; i < t + 1; ++i){
res = max(res, times[i]);
}
cout << res << endl;
return 0;
}
#include <iostream>
using namespace std;
const int N = 48;
const int White = 0, Black = 1;
int board[N][N], nx, ny, gx, gy;
bool dfs(int x, int y){
if (board[y][x] == White) return false;
if (x == gx && y == gy) return true;
board[y][x] = White;
int dx[] = { 0, -1, 1, 0 }, dy[] = { -1, 0, 0, 1 };
bool res = false;
for (int i = 0; i < 4; ++i){
int tx = x + dx[i], ty = y + dy[i];
if (0 <= tx && 0 <= ty && tx < nx && ty < ny && board[ty][tx] == Black){
res = res || dfs(tx, ty);
}
}
return res;
}
int main(){
int sx, sy, n;
for (int i = 0; i < N; ++i){
for (int j = 0; j < N; ++j){
board[i][j] = White;
}
}
cin >> ny >> nx;
cin >> sy >> sx >> gy >> gx;
--sx; --sy; --gx; --gy;
cin >> n;
for (int i = 0; i < n; ++i){
int r, c, h, w;
cin >> r >> c >> h >> w;
--r; --c;
for (int j = r; j < r + h; ++j){
for (int k = c; k < c + w; ++k){
board[j][k] = Black;
// cout << j << k << board[j][k] << endl;
}
}
}
/*
for (int i = 0; i < ny; ++i){
for (int j = 0; j < nx; ++j){
cout << board[i][j];
}
cout << endl;
}
*/
if (dfs(sx, sy)){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
// cin >> nx;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
const int INIT = -1;
const int N = 1e9 + 7;
string nouns[2];
int memo[1000][2];
int rec(string s, int idx){
int res = 0;
if (idx == s.length()) return 1;
for (int i = 0; i < 2; ++i){
if (memo[idx][i] != -1) res += memo[idx][i];
else{
string t = s.substr(idx, nouns[i].length());
if (t == nouns[i]){
res += memo[idx][i] = rec(s, idx + nouns[i].length()) % N;
}
else{
memo[idx][i] = 0;
}
res = res % N;
}
}
return res;
}
int main(){
string str;
for (int i = 0; i < 1000; ++i){
for (int j = 0; j < 2; ++j){
memo[i][j] = INIT;
}
}
cin >> str >> nouns[0] >> nouns[1];
cout << rec(str, 0) << endl;
// cin >> str;
return 0;
}
// WA
#include <iostream>
#include <algorithm>
using namespace std;
const int FIRST = 1, SECOND = 0, INIT = -1;
const int N = 500;
// 1: leave stone 2: can pick
int memo[N + 1][N + 1];
/*
int rec(int n, int p){
if (n == 0) return SECOND;
if (n <= p + 1) return FIRST;
for (int i = 1; i <= p; ++i){
rec(n - i, i);
if (all(n, i + 1, FIRST)) memo[n][i] = FIRST;
else if (all(n, i + 1, SECOND)) memo[n][i] = SECOND;
}
}
*/
bool all(int n, int p, int t){
bool res = true;
for (int k = 1; k < p && k <= n; ++k){
res = res && (memo[n - k][k] != INIT && memo[n - k][k] == 1 - t);
}
return res;
}
bool any(int n, int p, int t){
bool res = false;
for (int k = 1; k < p && k < n; ++k){
res = res || memo[n][k] == t;
}
return res;
}
int main(){
int n, p;
cin >> n >> p;
for (int i = 0; i <= N; ++i){
for (int j = 0; j <= N; ++j){
memo[i][j] = INIT;
}
}
for (int i = 0; i <= n; ++i){
memo[0][i] = SECOND;
}
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= (i != n ? p + 1 : p); ++j){
if (i <= j + 1) memo[i][j] = FIRST;
else if (all(i, j + 1, FIRST)) memo[i][j] = FIRST;
else if (all(i, j + 1, SECOND)) memo[i][j] = SECOND;
else memo[i][j] = INIT;
}
}
for (int i = n; i <= n; ++i){
cout << "case:" << i << endl;
for (int j = 0; j <= n; ++j){
cout << j << ":" << memo[i][j] << " ";
}
cout << endl;
}
if (any(n, p, FIRST)){
cout << "first" << endl;
}
else if (any(n, p, SECOND)){
cout << "second" << endl;
}
//cin >> n;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment