Integer Cards

题意:先给出n个数字,然后可以有m次操作,每次操作以数字对(x,y)表示最多能选x个数字把它变成y,问经历m次操作后n个数字和最大为多少?

解法:一个明显正确的做法是:用y尽量大的操作去改变数组,直到不能改变(产生负收益)为止。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int n,m,a[N];
struct dat{
int x,y;
bool operator < (const dat &rhs) const {
return y>rhs.y;
}
}b[N]; int main()
{
cin>>n>>m;
for (int i=;i<=n;i++) scanf("%d",&a[i]);
sort(a+,a+n+);
for (int i=;i<=m;i++) scanf("%d%d",&b[i].x,&b[i].y);
sort(b+,b+m+);
int nowa=,nowb=;
while (nowa<=n && nowb<=m) {
if (b[nowb].y<=a[nowa]) break;
for (int i=;i<=b[nowb].x;i++) {
if (nowa>n) break;
if (b[nowb].y<=a[nowa]) break;
a[nowa]=b[nowb].y; nowa++;
}
nowb++;
}
long long ans=;
for (int i=;i<=n;i++) ans+=(long long)a[i];
cout<<ans<<endl;
return ;
}

Cell Distance

题意:给出n*m的表格,每次选k个,然后计算这k个格子任两个欧几里得距离和。算出以上所有不同方案答案距离总和。

解法:这题一看题目明显往算贡献方面想。选k个格子方案数是C(n,m),然后k个格子任两个欧几里得距离有C(k,2)对,那么每一对的距离是多少呢?我们注意到每一对的距离都可能不尽相同,但是题目要求计算的是任两对的距离,那么我们就可以考虑用总数*平均得到总和,这里有一个结论:任两个格子的平均欧几里得距离是(n+m)/3。那么答案就是:C(n*m,k)*C(k,2)*(n+m)/3。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int P=1e9+;
const int N=2e5+;
int n,m,k;
LL fac[N],inv[N]; LL power(LL x,LL p) {
LL ret=;
for (;p;p>>=) {
if (p&) ret=ret*x%P;
x=x*x%P;
}
return ret;
} void prework() {
fac[]=; inv[]=power(fac[],P-);
for (int i=;i<=;i++) {
fac[i]=fac[i-]*i%P;
inv[i]=power(fac[i],P-);
}
} LL C(LL n,LL m) {
return fac[n]*inv[m]%P*inv[n-m]%P;
} int main()
{
prework();
cin>>n>>m>>k;
LL ans=C(n*m,k)%P*C(k,)%P*(n+m)%P*power(,P-)%P;
cout<<ans<<endl;
return ;
}

Absolute Minima

题意:每个给出操作或查询,操作是给出(a,b)然后f(x)=f(x)+|x-a|+b,查询是查询所有f(x)的最小值坐标x以及最小值f(x)。

解法:大但猜想最小值坐标是不是a的中位数,手动尝试几个(a,b)操作后发现确实是这样。那么这题就变成景经典的动态中位数问题了,用大根堆小根堆解法可以解决。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
priority_queue<int,vector<int>,greater<int> > q1;
priority_queue<int> q2;
LL sum,sum1,sum2; int main()
{
int n,m; cin>>m;
while (m--) {
int opt; scanf("%d",&opt);
if (opt==) {
int x,y; scanf("%d%d",&x,&y);
n++; sum+=y;
q1.push(x); sum1+=x;
while (!q1.empty() && !q2.empty() && q1.top()<q2.top()) {
sum1-=q1.top(); sum1+=q2.top();
sum2-=q2.top(); sum2+=q1.top();
int t=q1.top(); q1.pop();
q1.push(q2.top());
q2.pop(); q2.push(t);
}
if (q1.size()-q2.size()>=)
sum1-=q1.top(),sum2+=q1.top(),q2.push(q1.top()),q1.pop();
} else {
int mid;
if (n%) mid=q1.top(); else mid=q2.top();
LL ans=((LL)mid*(n/)-sum2)+(sum1-(LL)mid*(n-n/))+sum;
printf("%d %lld\n",mid,ans);
}
}
return ;
}

AtCoder Beginner Contest 127 D,E,F的更多相关文章

  1. AtCoder Beginner Contest 127 解题报告

    传送门 非常遗憾.当天晚上错过这一场.不过感觉也会掉分的吧.后面两题偏结论题,打了的话应该想不出来. A - Ferris Wheel #include <bits/stdc++.h> u ...

  2. 【AtCoder Beginner Contest 181】A~F题解

    越学越菜系列 于2020.11.2,我绿了(错乱) A - Heavy Rotation 签到题,奇数Black,偶数White. code: #include<bits/stdc++.h> ...

  3. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  4. AtCoder Beginner Contest 238 A - F 题解

    AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...

  5. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  6. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  7. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  8. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  9. AtCoder Beginner Contest 161

    比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...

随机推荐

  1. Angular的一些常用命令

    Angular的一些常用命令 cmd中创建项目: ng new taskmgr -si --style=scss //先不安装依赖,si 为skip install material需要scss样式的 ...

  2. Oracle Linux下使用sqlplus的edit命令

    1.使当前会话生效 define_editor=vi SQL> select * from dual; D - X SQL> edit Wrote file afiedt.buf 21 1 ...

  3. python数字图像处理(一)图像的常见操作

    首先导入必要的库,使用Opencv读入图像,避免复杂的图像解析,同时使用Opencv作为算法的对比,由于使用环境为jupyter使用matplotlib直接可视化 import cv2 import ...

  4. 使用Makefile编译Erlang

    #配置选项,可以是DEBUG和RELEASE CONFIG ?= RELEASE #语言配置,可以是chs(简体中文).cht(繁体中文)等等 Region ?= chs #源文件目录 SOURCE_ ...

  5. 使用egg.js和egg-sequelize连接mysql

    1.通过 egg-init 初始化一个项目: egg-init --type=simple --dir=sequelize-projectcd sequelize-projectnpm i 2.安装并 ...

  6. css3 实现可以中英切换的导航条

    html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

  7. Mongo 备份

    1. Windows下远程连接服务器上的MongoDB数据库 使用的是mongo命令,如果安装mongodb时配置了环境变量,可以直接快捷键windows+R打开cmd. Cmd  --- mongo ...

  8. Zip函数(Python)

    >>> z = zip((2,3,4),(33,44,55)) >>> z <zip object at 0x1022cdb88> >>&g ...

  9. cocos2D-X call JNIHelper

    #ifndef _WIN32 JNIEnv *j = JniHelper::getEnv(); if (j == nullptr || j == NULL) {test += "JNIEnv ...

  10. OC学习篇之---@property和@synthesize的使用

    在之前一片文章我们介绍了OC中的内存管理:http://blog.csdn.net/jiangwei0910410003/article/details/41924683,今天我们来介绍两个关键字的使 ...