https://vjudge.net/contest/172464

后来补题发现这场做的可真他妈傻逼

A.签到傻逼题,自己分情况

 #include <cstdio>
#include <vector>
#include <algorithm> using std::vector;
using std::sort; typedef long long ll; int n, m; ll a[], b[]; ll sa, sb, dis, tmp, qaq; int t1 = -, t2 = -; int a1, a2, a3, a4; struct node {
ll x, y, z;
bool operator < (const node &a) const {
return x < a.x;
}
}; vector <node> e; ll abs(ll x) {
return x < ? -x : x;
} node find1(ll x) {
node ret = {, -, -};
int l = , r = e.size() - , mid;
while(l <= r) {
int mid = (l + r) >> ;
if(e[mid].x * <= x) ret = e[mid], l = mid + ;
else r = mid - ;
}
return ret;
} node find2(ll x) {
node ret = {, -, -};
int l = , r = e.size() - , mid;
while(l <= r) {
int mid = (l + r) >> ;
if(e[mid].x * > x) ret = e[mid], r = mid - ;
else l = mid + ;
}
return ret;
} int main() {
scanf("%d", &n);
for(int i = ;i <= n;i ++)
scanf("%lld", &a[i]), sa += a[i];
scanf("%d", &m);
for(int i = ;i <= m;i ++)
scanf("%lld", &b[i]), sb += b[i];
if(abs(sa - sb) <= ) {
printf("%lld\n0\n", abs(sa - sb));
return ;
}
qaq = tmp = dis = sa - sb;
for(int i = ;i <= n;i ++)
for(int j = ;j <= m;j ++)
if(abs(qaq - (a[i] - b[j]) * ) < abs(dis))
dis = qaq - (a[i] - b[j]) * , t1 = i, t2 = j;
for(int i = ;i <= n;i ++)
for(int j = i + ;j <= n;j ++)
e.push_back((node){a[i] + a[j], i, j});
sort(e.begin(), e.end());
for(int i = ;i <= m;i ++)
for(int j = i + ;j <= m;j ++) {
ll k = b[i] + b[j];
node tt = find1(qaq + k * );
if(tt.y != - && abs(qaq + k * - tt.x * ) < abs(tmp)) tmp = qaq + k * - tt.x * , a1 = tt.y, a2 = i, a3 = tt.z, a4 = j;
tt = find2(qaq + k * );
if(tt.y != - && abs(qaq + k * - tt.x * ) < abs(tmp)) tmp = qaq + k * - tt.x * , a1 = tt.y, a2 = i, a3 = tt.z, a4 = j;
}
if(abs(qaq) <= abs(dis) && abs(qaq) <= abs(tmp)) printf("%lld\n0\n", abs(qaq));
else if(abs(dis) <= abs(tmp)) printf("%lld\n1\n%d %d", abs(dis), t1, t2);
else printf("%lld\n2\n%d %d\n%d %d", abs(tmp), a1, a2, a3, a4);
return ;
}

想写if-else结果写完if忘记else了

B.我是暴力的O(n^2logn)

首先如果只交换一个数,那O(n^2)都会算吧

那交换两个数呢,我把n个数两两结合并求和,再对他们排序

再枚举另一数组的数对,二分一下尝试更新答案

 #include <cstdio>
#include <vector>
#include <algorithm> using std::vector;
using std::sort; typedef long long ll; int n, m; ll a[], b[]; ll sa, sb, dis, tmp, qaq; int t1 = -, t2 = -; int a1, a2, a3, a4; struct node {
ll x, y, z;
bool operator < (const node &a) const {
return x < a.x;
}
}; vector <node> e; ll abs(ll x) {
return x < ? -x : x;
} node find1(ll x) {
node ret = {, -, -};
int l = , r = e.size() - , mid;
while(l <= r) {
int mid = (l + r) >> ;
if(e[mid].x * <= x) ret = e[mid], l = mid + ;
else r = mid - ;
}
return ret;
} node find2(ll x) {
node ret = {, -, -};
int l = , r = e.size() - , mid;
while(l <= r) {
int mid = (l + r) >> ;
if(e[mid].x * > x) ret = e[mid], r = mid - ;
else l = mid + ;
}
return ret;
} int main() {
scanf("%d", &n);
for(int i = ;i <= n;i ++)
scanf("%lld", &a[i]), sa += a[i];
scanf("%d", &m);
for(int i = ;i <= m;i ++)
scanf("%lld", &b[i]), sb += b[i];
if(abs(sa - sb) <= ) {
printf("%lld\n0\n", abs(sa - sb));
return ;
}
qaq = tmp = dis = sa - sb;
for(int i = ;i <= n;i ++)
for(int j = ;j <= m;j ++)
if(abs(qaq - (a[i] - b[j]) * ) < abs(dis))
dis = qaq - (a[i] - b[j]) * , t1 = i, t2 = j;
for(int i = ;i <= n;i ++)
for(int j = i + ;j <= n;j ++)
e.push_back((node){a[i] + a[j], i, j});
sort(e.begin(), e.end());
for(int i = ;i <= m;i ++)
for(int j = i + ;j <= m;j ++) {
ll k = b[i] + b[j];
node tt = find1(qaq + k * );
if(tt.y != - && abs(qaq + k * - tt.x * ) < abs(tmp)) tmp = qaq + k * - tt.x * , a1 = tt.y, a2 = i, a3 = tt.z, a4 = j;
tt = find2(qaq + k * );
if(tt.y != - && abs(qaq + k * - tt.x * ) < abs(tmp)) tmp = qaq + k * - tt.x * , a1 = tt.y, a2 = i, a3 = tt.z, a4 = j;
}
if(abs(qaq) <= abs(dis) && abs(qaq) <= abs(tmp)) printf("%lld\n0\n", abs(qaq));
else if(abs(dis) <= abs(tmp)) printf("%lld\n1\n%d %d", abs(dis), t1, t2);
else printf("%lld\n2\n%d %d\n%d %d", abs(tmp), a1, a2, a3, a4);
return ;
}

补题的时候,就把比赛代码三个地方的 int 改成了long long就过了

C.别人补题写的DP一眼看不懂...反正数据范围也不大,我们来xjb乱搞吧

数据范围20,时间5s,没有直接爆搜的思路

答案在0-1之间,满足单调性...试试二分?那judge呢?暴力dfs枚举?

效率玄学?并没有关系!...就当试试咯...过了...比DP还快...

 #include <cmath>
#include <cstdio>
#include <algorithm> using namespace std; const double eps = 1e-; int n, L[], R[]; double a[]; bool dfs(int i, int x) {
if(i > n)
return ;
int y = L[i] / x;
if(L[i] % x) y ++;
for(y *= x;y <= R[i];y += x)
if(dfs(i + , y))
return ;
return ;
} bool judge(double k) {
for(int i = ;i <= n;i ++)
L[i] = ceil(a[i] - a[i] * k), R[i] = floor(a[i] + a[i] * k);
for(int i = L[];i <= R[];i ++)
if(dfs(, i))
return ;
return ;
} int main() {
scanf("%d", &n);
for(int i = ;i <= n;i ++)
scanf("%lf", &a[i]);
double l = , r = 1.0, mid, ans;
for(int t = ;t --;) {
mid = (l + r) / ;
if(judge(mid)) ans = mid, r = mid - eps;
else l = mid + eps;
}
printf("%.12f", ans);
return ;
}

看了别人DP代码...看懂了...

f[i][j]代表把第 i 种货币变成 j 的最小答案

我们有一种无赖解是把所有货币都变0

所以对于第 i 种货币,从 0 枚举到 a[i] * 2 就可以啦

复杂度O(nklogk),  k = max(a[i]) = 20W

这么来说粗略计算我的做法复杂度就是O(nklogk * log(1/eps))...实际优太多

D.ans = C(n,3) - 不合法的三角形

对于非法三角形枚举最大边 z

再求 x + y <= z 的 (x,y) 有多少对即可

预处理,O(1)回答

 #include <cstdio>

 typedef long long ll;

 const int maxn = ;

 ll a[maxn], b[maxn];

 ll c(ll x) {
return x * (x - ) * (x - ) / ;
} int main() {
for(int i = ;i <= ;i ++) a[i] = (i + ) / - ;
for(int i = , j = ;i <= ;i ++) {
if(!(i & )) j ++;
b[i] = b[i - ] + j;
}
for(int i = ;i <= ;i ++) a[i] += a[i - ], b[i] += b[i - ];
int n;
while(scanf("%d", &n), n >= ) printf("%lld\n", c(n) - a[n] - b[n]);
return ;
}

E.

bupt summer training for 16 #3 ——构造的更多相关文章

  1. bupt summer training for 16 #8 ——字符串处理

    https://vjudge.net/contest/175596#overview A.设第i次出现的位置左右端点分别为Li,Ri 初始化L0 = 0,则有ans = sum{ (L[i] - L[ ...

  2. bupt summer training for 16 #7 ——搜索与DP

    https://vjudge.net/contest/174962#overview A.我们发现重点在于x,y只要累加就ok了 在每个x上只有上下两种状态,所以可以记忆化搜索 f[0/1][i]表示 ...

  3. bupt summer training for 16 #6 ——图论

    https://vjudge.net/contest/174020 A.100条双向边,每个点最少连2个边 所以最多100个点,点的标号需要离散化 然后要求恰好经过n条路径 快速幂,乘法过程就是flo ...

  4. bupt summer training for 16 #5 ——数据结构

    https://vjudge.net/contest/173780 A.假设 Pt = i,则由Ppi = i得 Ppt = t = Pi 所以就有 if Pt = i then Pi = t #in ...

  5. bupt summer training for 16 #4 ——数论

    https://vjudge.net/contest/173277#overview A.平方差公式后变为 n = (x + y)(x - y) 令 t = x - y ,变成 n = (t + 2x ...

  6. bupt summer training for 16 #2 ——计算几何

    https://vjudge.net/contest/171368#overview A.一个签到题,用叉积来判断一个点在一条线的哪个方向 可以二分,数据范围允许暴力 #include <cst ...

  7. bupt summer training for 16 #1 ——简单题目

    D.What a Mess 给n个数,求其中能满足 a[i] % a[j] == 0 的数对之和 n = 1W,max_ai = 100W 不是很大,所以就直接筛就可以了 计算可得最高复杂度 < ...

  8. STL——容器(Set & multiset)编译器提供的16种构造(挖个坑)

    Set & multiset 在vs2019编译器中提供了16种构造方法 1.默认的无参构造 2.比较容器内容,key_comp()函数返回一个比较key的函数. 3.使用迭代器的区间拷贝,拷 ...

  9. 【Android Developers Training】 16. 暂停和恢复一个Activity

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

随机推荐

  1. FileZilla文件下载的目录

    连接上ftp服务器之后,在remote site那边邮件选中了目录下载文件,但是下载完成之后. 不知道下载到哪里了,用search everything软件搜了一下,发现就在D盘的根目录. 所以,下载 ...

  2. openstack service glance-api/registry mysql of max_connection

  3. VMware 14 Pro 永久许可证激活密钥

    VMware 14 Pro 永久许可证激活密钥 FF31K-AHZD1-H8ETZ-8WWEZ-WUUVACV7T2-6WY5Q-48EWP-ZXY7X-QGUWD

  4. Lua相关回调总结【转】

    原文 http://www.zaojiahua.com/lua-callback-functions.html 最近做一个小项目,是用Lua写的,中间用到了很多的回调,基本Cocos中的那几种常用回调 ...

  5. C语言常量

    Constant包括4种类型: 整型 浮点型 枚举 字符型 #include <stddef.h> #include <uchar.h> int main() { /* Int ...

  6. [ USACO 2007 OPEN ] Dining

    \(\\\) \(Description\) 有\(N\)头牛,\(F\)种食物,\(D\)种饮料,每种食物和饮料只有一份. 现在已知每头牛可以吃哪些食物,可以喝哪些饮料,问最多可以让多少头牛可以同时 ...

  7. linux 安装 mongo

    整个安装过程:下载安装包--> 解压,添加系统路径(是滴,不用安装解压即可) --> 创建数据目录 --> 启动mongod服务 --> 运行mongo 1.下载安装包 Mon ...

  8. html——相对路径、绝对路径(有待补充....)

    相对路径主要看你访问的文件相对自己的页面在哪个文件夹下.如果自己藏的很深,必须用“../”跳出.如果项目中的文件位置分布是这样: 那么index页面若要访问这两张图片就需要用相对路径: <img ...

  9. [Windows Server 2003] 安装网站伪静态

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装IIS伪静 ...

  10. 实验2 C++数组与指针

    一.实验目的: 掌握一维数组和二维数组的定义.赋值和输入输出的方法. 掌握字符数组和字符串函数的使用. 通过实验进一步掌握指针的概念,会定义和使用指针变量. 能正确使用数组的指针和指向数组的指针变量. ...