This blog is YMx's. Please follo|

园龄:粉丝:关注:

10.09模拟赛总结

总结

考场估分:[0,95]+100+0+[0,20]=[100,215]

实际得分:40+100+0+20=160,寄寄寄寄寄寄寄寄寄寄。

T1 dist

题意

有一条直线 y=k,两点 PQ,求直线上一点 R 使得 PR+RQ 的值最小。

分析

将军饮马模板,但是不会/fn/fn/fn

时间复杂度显然 Θ(1)

寄因

挂分:60pts

原因:小学就学了的将军饮马,但是我没学/fn/fn/fn/fn/fn

代码

点击查看代码
#include <bits/stdc++.h>

#define int long long

using namespace std;

int k;
int x, y, x2, y2;

int dist(int x, int y, int x2, int y2) {
  return (x - x2) * (x - x2) + (y - y2) * (y - y2);
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> k >> x >> y >> x2 >> y2;
  if (y > y2) {
    swap(y, y2);
    swap(x, x2);
  }
  if (y <= k && k <= y2) {
    cout << dist(x, y, x2, y2) << '\n';
  } else if (k < y) {
    cout << min(dist(x, k - (y - k), x2, y2), dist(x, y, x2, (k - (y2 - k)))) << '\n';
  } else if (k > y2) {
    cout << min(dist(x, y, x2, k + k - y2), dist(x, k + k - y, x2, y2)) << '\n';
  }
  return 0;
}

T2 shoot

题意

有一堆区间,每个区间内部有一个子区间,询问几次,每次给定一个坐标,问这个坐标在哪个区间里,如果不在区间里输出 Failed,如果已经到过这个区间输出 Again,如果在这个区间的子区间里输出 Perfect,如果在这个区间里输出 Normal

分析

要么离散化然后线段树,要么直接二分函数,要么手打二分。

时间复杂度均为 Θ(klogn),但显然后者常数更优。

部分分

对于 30% 的数据,1n,k1000,暴力找区间就行了。

对于另 20% 的数据,1m,li,ri106,线段树维护一下。

对于另 30% 的数据,li=xi,ri=yi,不用判断 Normal 的情况。

寄因

挂分:0pts

原因:没挂。

代码

点击查看代码
#include <bits/stdc++.h>

#define int long long

using namespace std;

/* --------------- fast io --------------- */  // begin
namespace Fread {
const int SIZE = 1 << 21;
char buf[SIZE], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, SIZE, stdin);
    if (S == T) return '\n';
  }
  return *S++;
}
}  // namespace Fread
namespace Fwrite {
const int SIZE = 1 << 21;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush() {
  fwrite(buf, 1, S - buf, stdout);
  S = buf;
}
inline void putchar(char c) {
  *S++ = c;
  if (S == T) flush();
}
struct NTR {
  ~NTR() { flush(); }
} ztr;
}  // namespace Fwrite
#ifdef ONLINE_JUDGE
#define getchar Fread ::getchar
#define putchar Fwrite ::putchar
#endif
namespace Fastio {
struct Reader {
  template <typename T>
  Reader& operator>>(T& x) {
    char c = getchar();
    T f = 1;
    while (c < '0' || c > '9') {
      if (c == '-') f = -1;
      c = getchar();
    }
    x = 0;
    while (c >= '0' && c <= '9') {
      x = x * 10 + (c - '0');
      c = getchar();
    }
    x *= f;
    return *this;
  }
  Reader& operator>>(char& c) {
    c = getchar();
    while (c == ' ' || c == '\n') c = getchar();
    return *this;
  }
  Reader& operator>>(char* str) {
    int len = 0;
    char c = getchar();
    while (c == ' ' || c == '\n') c = getchar();
    while (c != ' ' && c != '\n' && c != '\r') {  // \r\n in windows
      str[len++] = c;
      c = getchar();
    }
    str[len] = '\0';
    return *this;
  }
  Reader() {}
} cin;
const char endl = '\n';
struct Writer {
  template <typename T>
  Writer& operator<<(T x) {
    if (x == 0) {
      putchar('0');
      return *this;
    }
    if (x < 0) {
      putchar('-');
      x = -x;
    }
    static int sta[45];
    int top = 0;
    while (x) {
      sta[++top] = x % 10;
      x /= 10;
    }
    while (top) {
      putchar(sta[top] + '0');
      --top;
    }
    return *this;
  }
  Writer& operator<<(char c) {
    putchar(c);
    return *this;
  }
  Writer& operator<<(char* str) {
    int cur = 0;
    while (str[cur]) putchar(str[cur++]);
    return *this;
  }
  Writer& operator<<(const char* str) {
    int cur = 0;
    while (str[cur]) putchar(str[cur++]);
    return *this;
  }
  Writer() {}
} cout;
}  // namespace Fastio
#define cin Fastio ::cin
#define cout Fastio ::cout
#define endl Fastio ::endl
/* --------------- fast io --------------- */  // end

const int kMaxN = 1e5 + 5;

int n, m, k;
struct Node {
  int l, r;
  int x, y;
  friend bool operator<(const Node& a, const Node& b) {
    return a.l < b.l;
  }
} a[kMaxN];
bool vis[kMaxN];

signed main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].l >> a[i].x >> a[i].y >> a[i].r;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= k; i++) {
    int x;
    cin >> x;
    int l = 1, r = n;
    while (l < r) {
      int mid = l + r >> 1;
      if (a[mid].r < x) {
        l = mid + 1;
      } else {
        r = mid;
      }
    }
    if (x < a[l].l || x > a[l].r) {
      cout << "Failed";
    } else if (vis[l]) {
      cout << "Again";
      vis[l] = 1;
    } else if (x >= a[l].x && x <= a[l].y) {
      cout << "Perfect";
      vis[l] = 1;
    } else {
      cout << "Normal";
      vis[l] = 1;
    }
    cout << '\n';
  }
  return 0;
}

T3 max

题意

给定长 n 的序列 a,求最大的 1lrn|i=lrai|

分析

分两种情况乱搞讨论,显然对于绝对值只有两种可能:负数或者正数,没了,ST 表维护一下前缀和最大值,可以了。

时间复杂度 Θ(mlogn)

寄因

挂分:20pts

原因:打表打的太忘我,代码 34.53MB。。。

代码

点击查看代码
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int kMaxN = 2e5 + 5;

int n, q;
ll sum[kMaxN + 5], stmn[kMaxN + 5][20], stmx[kMaxN + 5][20];
int lg2[kMaxN + 5];

ll qmn(int l, int r) {
  if (l > r) {
    return 1e18;
  }
  if (l == 0) {
    return min(0ll, qmn(l + 1, r));
  }
  int k = lg2[r - l + 1];
  return min(stmn[l][k], stmn[r - (1 << k) + 1][k]);
}
ll qmx(int l, int r) {
  if (l > r) {
    return -1e18;
  }
  if (l == 0) {
    return max(0ll, qmx(l + 1, r));
  }
  int k = lg2[r - l + 1];
  return max(stmx[l][k], stmx[r - (1 << k) + 1][k]);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> q;
  for (int i = 2; i <= n; i++) lg2[i] = lg2[i >> 1] + 1;
  for (int i = 1; i <= n; i++) {
    ll t;
    cin >> t;
    sum[i] = sum[i - 1] + t;
    stmn[i][0] = stmx[i][0] = sum[i];
  }
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      stmn[i][j] = min(stmn[i][j - 1], stmn[i + (1 << (j - 1))][j - 1]);
      stmx[i][j] = max(stmx[i][j - 1], stmx[i + (1 << (j - 1))][j - 1]);
    }
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    ll mx = qmx(l, r), mn = qmn(l, r);
    cout << mx - mn << '\n';
  }
  return 0;
}

T4 skill

题意

n 个二元组 (Ai,Bi),选择一个二元组的排列,使得:

  • 1i<nAi=Ai+1Bi=Bi+1

  • 1<i<n¬(Ai1=Ai=Ai+1Bi1=Bi=Bi+1)

如果有解,输出 Yes 并输出字典序最小的排列;否则输出 No

分析

扬跃顶真,鉴定为:图论凸轮,我们可以把 (a,b) 这个二元组看成一条边,然后找一下欧拉回路就行了,因为要求字典序最小,所以把边按输入顺序排下序就行了。如果只有欧拉路径,那么可以在起点与终点之间连一条下标为 0 的边,然后当欧拉路径处理就行了。

时间复杂度很小的 Θ(n),但是排序就有 Θ(nlogn) 了。

寄因

挂分:0pts

原因:没挂,只打了暴力,这就是暴力带给我的自信。

代码

点击查看标程
// 你觉得我会有标程吗(
// 还真有(
#include <bits/stdc++.h>
// #define int long long
#define ll long long
#define db double
#define fi first
#define se second
#define pii pair<int, int>
#define vi vector<int>

using namespace std;

const int maxn = 1e6;

int n, a[maxn + 5], b[maxn + 5];
vector<pii> g[maxn + 5];
int vis[maxn + 5];
int ans[maxn + 5], cnt, deg[maxn + 5], cur[maxn + 5];

int ANS[maxn + 5], P[maxn + 5], pcnt;
bool cmp(pii x, pii y) {
  return x.se < y.se;
}
void dfs(int u) {
  for (int i = cur[u]; i < g[u].size(); i = cur[u]) {
    int v = g[u][i].fi, w = g[u][i].se;
    cur[u] = i + 1;
    if (vis[w]) continue;
    vis[w] = 1;
    dfs(v);
    ans[++cnt] = w;
  }
}
void upd() {
  for (int i = 1; i <= n; i++) {
    if (ans[n - i + 1] > ANS[i])
      return;
    else if (ans[n - i + 1] == ANS[i])
      continue;
    else {
      for (int j = 1; j <= n; j++) {
        ANS[j] = ans[n - j + 1];
      }
      return;
    }
  }
}
void solve(int p) {
  cnt = 0;
  for (int i = 1; i <= 2 * n; i++) vis[i] = 0, cur[i] = 0;
  dfs(p);
  if (cnt != n) {
    puts("No");
    exit(0);
  }
  upd();
}
int main() {
  // freopen("skill.in", "r", stdin);
  // freopen("skill.out", "w", stdout);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i], &b[i]);
    deg[a[i]]++, deg[b[i] + n]++;
    g[a[i]].push_back({b[i] + n, i});
    g[b[i] + n].push_back({a[i], i});
    ANS[i] = 1e9;
  }
  for (int i = 1; i <= 2 * n; i++) sort(g[i].begin(), g[i].end(), cmp);
  for (int i = 1; i <= 2 * n; i++) {
    if (deg[i] > 0) {
      if (deg[i] & 1) P[++pcnt] = i;
    }
  }
  if (pcnt > 2) {
    puts("No");
    return 0;
  }
  if (pcnt == 2) {
    solve(P[1]);
    solve(P[2]);
  } else {
    solve(a[1]);
    solve(b[1] + n);
  }
  cout << "Yes" << '\n';
  for (int i = 1; i <= n; i++) {
    cout << ANS[i] << ' ';
  }
  return 0;
}
点击查看代码
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(0);\
	cin.tie(0), cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int kMaxN = 5e5 + 5;

int n;
int a, b, fa, fb;
bool vis[kMaxN << 1];
int cnt;
int deg[kMaxN << 1];
int cur[kMaxN << 1];

vector<int> p;
int ans[kMaxN << 1];
int val[kMaxN << 1];

vector<pii> l[kMaxN << 1];

void dfs(int u) {
	for (int i = cur[u]; i < l[u].size(); i = cur[u]) {
		int v = l[u][i].second, w = l[u][i].first;
		cur[u] = i + 1;
		if (vis[w]) {
			continue;
		}
		vis[w] = 1;
		dfs(v);
		ans[++cnt] = w;
	}
}

void upd() {
	for (int i = 1; i <= n; i++) {
		if (ans[n - i + 1] > val[i]) {
			return;
		} else if (ans[n - i + 1] == val[i]) {
			continue;
		} else {
			for (int j = 1; j <= n; j++) {
				val[j] = ans[n - j + 1];
			}
			return;
		}
	}
}

void solve(int p) {
	cnt = 0;
	for (int i = 1; i <= n << 1; i++) {
		vis[i] = 0, cur[i] = 0;
	}
	dfs(p);
	if (cnt != n) {
		puts("No");
		exit(0);
	}
	upd();
}

signed main() {
	IOS;
	cin >> n;
	cin >> fa >> fb;
	l[fa].push_back({1, fb + n});
	l[fb + n].push_back({1, fa});
	deg[fa]++, deg[fb + n]++;
	val[1] = 0x3f3f3f3f;
	for (int i = 2; i <= n; i++) {
		cin >> a >> b;
		l[a].push_back({i, b + n});
		l[b + n].push_back({i, a});
		deg[a]++, deg[b + n]++;
		val[i] = 0x3f3f3f3f;
	}
	for (int i = 1; i <= n << 1; i++) {
		stable_sort(l[i].begin(), l[i].end(), [](const pii & a, const pii & b) {
			return a.first < b.first;
		});
	}
	for (int i = 1; i <= n << 1; i++) {
		if (deg[i] > 0 && deg[i] & 1) {
			p.push_back(i);
		}
	}
	if (p.size() > 2) {
		puts("No");
		return 0;
	}
	if (p.size() == 2) {
		solve(p[0]);
		solve(p[1]);
	} else {
		solve(fa);
		solve(fb + n);
	}
	cout << "Yes\n";
	for (int i = 1; i <= n; i++) {
		cout << val[i] << ' ';
	}
	return 0;
}

本文作者:Yun_Mengxi

本文链接:https://www.cnblogs.com/Yun-Mengxi/p/17751889.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Yun_Mengxi  阅读(14)  评论(1编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起