Skip to content

Instantly share code, notes, and snippets.

@brycetsao
Created December 9, 2015 13:04
Show Gist options
  • Save brycetsao/7c961181fbd3a479eca4 to your computer and use it in GitHub Desktop.
Save brycetsao/7c961181fbd3a479eca4 to your computer and use it in GitHub Desktop.
PTC
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int n, L, Wa, Wb;
typedef struct
{
int v, w;
double cp;
} item;
item a[40];
struct Cmp {
bool operator()(const item& lhs, const item& rhs){
return lhs.cp > rhs.cp;
}
};
int mx = 0, sum_w = 0, sum_v = 0;
bool flag = false;
void g(int now, int size)
{
if(now == size){
if(sum_w >= Wa && sum_w <= Wb){
flag = true;
mx = ceil(double(sum_v) / sum_w);
return;
}
} else {
for(int i = now; i < n; ++i){
sum_w += a[i].w;
sum_v += a[i].v;
g(now + 1, size);
sum_v -= a[i].v;
sum_w -= a[i].w;
if(flag) return;
}
}
}
int f()
{
sort(a, a + n, Cmp());
for(int i = L; i <= n; ++i){
flag = false;
g(0, i);
if(mx) break;
}
flag = false;
return mx;
/*
int sum_v = 0, sum_w = 0;
int i;
for(i = 0; i < n && sum_w < Wa; ++i)
{
sum_w += a[i].w;
sum_v += a[i].v;
}
--i;
while(sum_w > Wb)
{
sum_w -= a[i].w;
sum_v -= a[i].v;
for(int i = 0; i < count; ++i)
{
}
}
return ceil(sum_w / sum_v);*/
}
int main(int argc, char const *argv[])
{
while(cin >> n && ~n)
{
if(!n) continue;
cin >> L >> Wa >> Wb;
for(int i = 0; i < n; ++i)
{
int v, w;
cin >> v >> w;
a[i] = {v, w, double(v)/w};
}
cout << f() << endl;
mx = 0;
}
return 0;
}
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
#define INF 1e9
//const double K = sqrt(3 + 2 * sqrt(2)), C = 1 / (1 + 3 * sqrt(2));
const double K = tan(3.1416/8);
char c;
typedef struct
{
int x, y;
} point;
point ary[100];
int n;
/*
void print()
{
for (int i = 0; i <= n; ++i)
{
printf("(%d,%d)\n", ary[i].x, ary[i].y);
}
}
*/
/*
double ftan(double a, double b)
{
return (a - b) / (1 + a * b);
}
*/
double slope(point& a, point& b)
{
int dx = b.x - a.x;
double dy = b.y - a.y;
if(!dx) return 2;
double res = dy / dx;
if(abs(res) > 1 / K) return 2;
if(abs(res) < K) return 1;
else return res > 0 ? 4 : 3;
}
void f()
{
double a, s;
a = slope(ary[0], ary[(n - 1) / 4]);
s = slope(ary[0], ary[n - 1]);
//double t = ftan(s, a);
//cout << t << ' ' << s<<endl;
if(a - s)
{
puts("E");
}
else cout << char('A' - 1 + a) << endl;
}
int main(int argc, char const *argv[])
{
while(cin >> c) // [
{
for(n = 0; cin >> c && c != ']'; ++n)
{
//scanf("%d,%d)", &ary[n].x, &ary[n].y);
cin >> ary[n].x;
cin >> c;
cin >> ary[n].y;
cin >> c;
}
f();
}
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
const int dx[9] = {0, 1, 1, 0, -1, -1, -1, 0, 1};
const int dy[9] = {0, 0, -1, -1, -1, 0, 1, 1, 1};
int n, q;
int x, y, k;
int mod;
string map[1000 + 5];
struct pnt
{
int x, y;
};
int vis[1005][1005];
pnt point[1005 * 1005];
void f()
{
for (int i = 0; i < 1005; ++i)
{
for (int j = 0; j < 1005; ++j)
{
vis[i][j] = 0;
}
}
int now = 0, preX , preY, mod = 0, newx, newy;
while(!vis[y][x] && k--){
vis[y][x] = now;
point[now++] = {x, y};
preX = x;
preY = y;
newx = dx[map[y][x] - '0'];
newy = dy[map[y][x] - '0'];
x += newx;
y += newy;
if(map[y][x] == 'x'){
cout << preX << ' ' << preY << endl; //
return;
}
else if(x < 0 || y < 0 || x == n || y == n){
cout << preX << ' ' << preY << endl; //
return;
}
}
if(!k){
cout << x << ' ' << y << endl;
return;
}
mod = now - vis[y][x];
cout << point[k % mod + vis[y][x]].x << ' ' << point[k % mod + vis[y][x]].y << endl;
}
int main()
{
while(cin >> n >> q){
for(int i = 0; i < n; ++i){
cin >> map[i];
}
while(q--){
mod = 0;
//fill(circle, circle + 1000 * 1000 + 5, 0);
cin >> x >> y >> k;
f();
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment