CF #488 Div2

A

模拟

#include <bits/stdc++.h>

using namespace std;

int a[100];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int mask = 0;
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    mask |= 1 << x;
  }
  for (int i = 0; i < n; i++) {
    if ((mask >> a[i]) & 1) {
      printf("%d ", a[i]);
    }
  }
  printf("\n");
  return 0;
}

B

开个堆搞一搞。

#include <bits/stdc++.h>

using namespace std;

const int N = 100010;

int n, k;
int s[N], v[N], o[N];
long long res[N];

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  if (k == 0) {
    for (int i = 0; i < n; i++) {
      printf("%d%c", v[i], " \n"[i == n - 1]);
    }
    return 0;
  }
  iota(o, o + n, 0);
  sort(o, o + n, [](int x, int y) {
    return s[x] < s[y];
  });
  multiset<int> heap;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int ii = o[i];
    res[ii] = sum + v[ii];
    if ((int) heap.size() < k) {
      sum += v[ii];
      heap.emplace(v[ii]);
    } else if (v[ii] > *(heap.begin())) {
      sum += v[ii] - *(heap.begin());
      heap.erase(heap.begin());
      heap.emplace(v[ii]);
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%lld%c", res[i], " \n"[i == n - 1]);
  }
  return 0;
}

C

枚举一下平面上的点,看看有没有公共的。

#include <bits/stdc++.h>

using namespace std;

const int inf = 2e9;

struct square {
  int xmin;
  int xmax;
  int ymin;
  int ymax;

  square() {
    xmin = inf;
    xmax = -inf;
    ymin = inf;
    ymax = -inf;
    for (int i = 0; i < 4; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      xmin = min(xmin, x);
      xmax = max(xmax, x);
      ymin = min(ymin, y);
      ymax = max(ymax, y);
    }
  }

  bool inside(int x, int y) {
    return xmin <= x && x <= xmax && ymin <= y && y <= ymax;
  }

  bool inside2(int x, int y) {
    if (x < xmin || xmax < x) {
      return false;
    }
    int diff = abs(x - (xmin + xmax) / 2);
    return ymin + diff <= y && y <= ymax - diff;
  }
};

int main() {
  square a = square();
  square b = square();
  for (int x = -100; x <= 100; x++) {
    for (int y = -100; y <= 100; y++) {
      if (a.inside(x, y) && b.inside2(x, y)) {
        puts("yes");
        return 0;
      }
    }
  }
  puts("no");
  return 0;
}

D

沙雕文字游戏题。

#include <bits/stdc++.h>

using namespace std;

const int N = 20;

int n, m;
pair<int, int> a[N], b[N];

int match(pair<int, int>& a, pair<int, int>& b) {
  if (a == b) {
    return -1;
  }
  if (a.first == b.first) {
    return a.first;
  }
  if (a.first == b.second) {
    return a.first;
  }
  if (a.second == b.first) {
    return a.second;
  }
  if (a.second == b.second) {
    return a.second;
  }
  return -1;
}

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i].first, &a[i].second);
    if (a[i].first > a[i].second) {
      swap(a[i].first, a[i].second);
    }
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &b[i].first, &b[i].second);
    if (b[i].first > b[i].second) {
      swap(b[i].first, b[i].second);
    }
  }
  vector< set<int> > sa(n), sb(m);
  set<int> v;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int res = match(a[i], b[j]);
      if (res == -1) {
        continue;
      }
      v.emplace(res);
      sa[i].emplace(res);
      sb[j].emplace(res);
    }
  }
  if ((int) v.size() == 1) {
    printf("%d\n", *(v.begin()));
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if ((int) sa[i].size() > 1) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if ((int) sb[i].size() > 1) {
      puts("-1");
      return 0;
    }
  }
  puts("0");
  return 0;
}

E

钦定某些船对射,统计下每个 \(y\) 的贡献然后拼一拼。

#include <bits/stdc++.h>

using namespace std;

map< int, pair<long long, long long> > mp;
int a[100], b[100];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      mp[a[i] + b[j]].first |= 1ll << i;
      mp[a[i] + b[j]].second |= 1ll << j;
    }
  }
  int ans = 0;
  for (auto x : mp) {
    for (auto y : mp) {
      ans = max(ans, __builtin_popcountll(x.second.first | y.second.first) + __builtin_popcountll(x.second.second | y.second.second));
    }
  }
  printf("%d\n", ans);
  return 0;
}

常识和思考

  • E 在处理小数时要非常小心,\(-1 / 2 = 1 / 2\) 卡了半天。。。

原文地址:https://www.cnblogs.com/arg-53/p/9196450.html

时间: 2024-11-14 12:52:44

CF #488 Div2的相关文章

CF #261 div2 D. Pashmak and Parmida&amp;#39;s problem (树状数组版)

Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak. There is a sequence a that consists of n

CF #261 DIV2 A,B,C,D

A 先判断邻边长度是否相等,不是就无法构成正方形,否则的话位置坐标搞一下 #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <bitset> #include <vector> #include <set>

CF#215 DIV2: B. Sereja and Suffixes

Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1,?l2,?...,?lm (1?≤?li?≤?n). For each number li he wants to know

cf#261 div2 解题报告

.....代码没什么可说的,主要是学习各路大神姿势 A题 化简化简水题,都告诉平行坐标轴了,数据还出了对角线,后面两个点坐标给的范围也不错 ........和最优代码相比姿势有点混乱 #include <cstdio> int x[4],y[4]; int abs(int n){ return n<0?-n:n; } int main(){ scanf("%d%d%d%d",x,y,x+1,y+1); int dx=abs(x[0]-x[1]); int dy=abs

cf 301 div2

A - Combination Lock 题目大意:给有n个(0-9)环圈密码锁,数串 s1->s2最少移动次数: 题目分析: 简单模拟: 代码: const int N=100007; char s1[N],s2[N]; int main() { int n; while(scanf("%d",&n)==1) { int ans=0; scanf("%s%s",s1+1,s2+1); for(int i=1;i<=n;i++) { int a=

CF R631 div2 1330 E Drazil Likes Heap

LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了一下就没了. 但是到E就只剩下30min(都怪A B浪费我过多时间. 观察题目中给的一个程序 其维护了一个大根堆且这个程序意思是一个函数 这个函数是指对于这个大根堆上的一个非空节点来说每次会将这个值给删掉继承最大的儿子值 然后递归值最大的儿子值得某个节点没有一个非空儿子(那么这个点的值被删掉为0.

CF 313 DIV2 B 树状数组

http://codeforces.com/contest/313/problem/B 题目大意 给一个区间,问你这个区间里面有几个连续相同的字符. 思路: 表示个人用树状数组来写的...了解了树状数组的本质就行了. 当然用sum[r]-sum[l]也是可以的

CF #327 DIV2 D、E

两题都不难. 对于D题,可以使用相对移动,把吹aircraft移动变成相反方向的待援点的移动.假设此时时间为t,把aircraft的速度设为Vmax,看待援点在飞船最大速度飞行t秒的范围内,注意风向变化的时间点即可.其实很明显的二分.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 6 using namespace std; 7

CF R274 Div2 E Riding in a Lift DP

先预处理出能到当前点的区间,然后通过前缀和求得当前值即可. #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <stack> #include <map> #include <set> #include <climits> #include <iostream> #include &