2019년 바이두의 별·프로그래밍대회 - 1차전 1001100210031005
8540 단어 레코드
/*
* [ ]:
*
* [ ]: n 。
* [ ]: 。
*
* [tricks]:
*
* [ ]:
*
* */
#include
#define ll long long
#define all(x) (x).begin(),(x).end()
using namespace std;
void scan() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int maxn = 1e6 + 7;
ll a[maxn], b[maxn];
int main() {
scan();
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = n; i >= 1; i--) {
if (a[i] == 0 && b[i] == 0) continue;
if (a[i] == 0 && b[i]) cout << "0/1" << endl;
else if (b[i] == 0 && a[i]) cout << "1/0" << endl;
else if (a[i] && b[i]) {
cout << (a[i] / __gcd(a[i], b[i])) << "/" << b[i] / __gcd(a[i], b[i]) << endl;
}
goto ed;
}
ed:;
}
return 0;
}
제목 링크: 게임
/*
* [ ]:http://acm.hdu.edu.cn/showproblem.php?pid=6669
*
* [ ]:
*
* [ ]: , 。
*
* , 。
*
* [tricks]:
*
* [ ]:t*(2*n)*(6*n)
*
* */
#include
#define ll long long
#define all(x) (x).begin(),(x).end()
using namespace std;
void scan() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int maxn = 1e6 + 7;
struct node {
int l, r;
} a[maxn];
int point[maxn], cnt, n;
ll gao(int x) {
ll ret = -1;
int now[6], nxt[6];
memset(now, 0, sizeof(now));
for (int i = 0; i < n; i++) {
int l = a[i].l, r = a[i].r;
if (l <= x && x <= r) {
if (l == x) now[0] = -1;
if (r == x) now[2] = -1;
} else {
int goal = l;
if (x > r) goal = r;
memset(nxt, -1, sizeof(nxt));
for (int dx = 0; dx < 3; dx++) {
if (now[dx] == -1) continue;
for (int dy = 0; dy < 3; dy++) {
int ox = x + dx - 1, nx = goal + dy - 1;
if (l <= nx && nx <= r) {
int v = now[dx] + (fabs(nx - ox) + 1) / 2;
if (nxt[dy] == -1 || nxt[dy] > v) nxt[dy] = v;
}
}
}
x = goal;
memcpy(now, nxt, sizeof(now));
}
}
for (int i = 0; i < 3; i++) {
if (now[i] != -1 && (ret == -1 || ret > now[i]))
ret = max(now[i] * 1ll, ret);
}
return ret;
}
int main() {
scan();
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a[i].l >> a[i].r;
point[cnt++] = a[i].l, point[cnt++] = a[i].r;
}
sort(point, point + cnt);
cnt = unique(point, point + cnt) - point;
ll ans = 1e18;
for (int i = 0; i < cnt; i++) ans = min(gao(point[i]), ans);
cout << ans << endl;
}
return 0;
}
제목 링크: Seq
/*
* [ ]:
*
* [ ]: n , 。
* [ ]:
*
* [tricks]:
*
* [ ]:
*
* */
#include
#define ll long long
#define all(x) (x).begin(),(x).end()
using namespace std;
void scan() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int maxn = 1e6 + 7;
ll a[maxn], b[maxn];
ll fir[6] = {3, 1, 1, 0, 3, 0};
ll base[6] = {3, 4, 3, 1, 6, 1};
int main() {
scan();
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
cout << (fir[n % 6] + base[n % 6] * ((n - 1) / 6)) << endl;
}
// 4 3 1 6 1 3
// 1,1,0,3,0,3,
// 5,4,1,9,1,6,
// 9,7,2,15,2,9,
// 13,10,3,21,3,12,
// 17,13,4,27,4,15,
// int t;
// cin >> t;
// while (t--) {
// ll n;
// cin >> n;
//
// }
return 0;
}
제목 링크: Mindis
#include
#define ll long long
#define all(x) (x).begin(),(x).end()
using namespace std;
void scan() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int maxn = 250;
const int MAXM = 405;
int px[maxn * 2], py[maxn * 2], ix, iy, n;
int Ax, Ay, Bx, By;
struct Rectangle {
int l, r, t, b;
} rec[maxn];
int sped[MAXM * MAXM][4];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
struct Node {
double d, x, y;
Node() {}
Node(double _d, int _x, int _y) {
d = _d;
x = _x;
y = _y;
}
bool operator a.d;
}
};
priority_queue que;
double dist[MAXM * MAXM];
bool vis[MAXM * MAXM];
int findX(int x) { return lower_bound(px, px + ix, x) - px; }
int findY(int x) { return lower_bound(py, py + iy, x) - py; }
inline int Abs(int x) {
if (x < 0) return -x;
return x;
}
inline int check(int a, int b, int c, int d, int i) {
if (!(rec[i].l <= a && a <= rec[i].r && rec[i].b <= b && b <= rec[i].t)) return 0;
if (!(rec[i].l <= c && c <= rec[i].r && rec[i].b <= d && d <= rec[i].t)) return 0;
return 1;
}
inline void solve(int T) {
scanf("%d", &n);
ix = iy = 0;
for (int i = 0; i < n; i++) {
scanf("%d %d %d %d", &rec[i].l, &rec[i].b, &rec[i].r, &rec[i].t);
px[ix++] = rec[i].l;
px[ix++] = rec[i].r;
py[iy++] = rec[i].b;
py[iy++] = rec[i].t;
}
scanf("%d %d %d %d", &Ax, &Ay, &Bx, &By);
int INF = Abs(Ax - Bx) + Abs(Ay - By);
px[ix++] = Ax;
px[ix++] = Bx;
py[iy++] = Ay;
py[iy++] = By;
sort(px, px + ix);
sort(py, py + iy);
ix = unique(px, px + ix) - px;
iy = unique(py, py + iy) - py;
Ax = findX(Ax);
Bx = findX(Bx);
Ay = findY(Ay);
By = findY(By);
for (int i = 0; i < n; i++) {
rec[i].l = findX(rec[i].l);
rec[i].r = findX(rec[i].r);
rec[i].b = findY(rec[i].b);
rec[i].t = findY(rec[i].t);
}
memset(sped, 0, sizeof(sped));
for (int i = 0; i < ix; i++) {
for (int j = 0; j < iy; j++) {
for (int k = 0; k < 4; k++) {
int ni = i + dx[k], nj = j + dy[k];
int cnt = 0;
if (0 <= ni && ni < ix && 0 <= nj && nj < iy) {
for (int p = 0; p < n; p++) cnt += check(i, j, ni, nj, p);
}
sped[i * iy + j][k] = cnt;
}
}
}
int tot = ix * iy;
for (int i = 0; i < tot; i++) dist[i] = INF;
dist[Ax * iy + Ay] = 0;
memset(vis, false, sizeof(vis));
while (!que.empty()) que.pop();
que.push(Node(0, Ax, Ay));
while (!que.empty()) {
Node now = que.top();
que.pop();
int x = now.x, y = now.y, idx = x * iy + y;
if (vis[idx]) continue;
vis[idx] = true;
for (int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (0 <= nx && nx < ix && 0 <= ny && ny < iy) {
int nidx = nx * iy + ny;
int s = sped[idx][k] + 1, l = Abs(px[nx] - px[x]) + Abs(py[ny] - py[y]);
double t = (double) l / (double) s;
if (dist[nidx] > dist[idx] + t) {
dist[nidx] = dist[idx] + t;
que.push(Node(dist[nidx], nx, ny));
}
}
}
}
printf("%.5f
", dist[Bx * iy + By]);
}
int main() {
scan();
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = 0;
scanf("%d", &T);
for (int i = 1; i <= T; i++) solve(i);
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
react 비계 프로젝트는 https 방법으로텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.