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. java问题解读,String类为什么是final的

    一.理解final 望文生义,final意为“最终的,最后的”,我理解为“不能被改变的”,它可以修饰类.变量和方法. 所以我是否可以理解为被它所修饰的类.变量和方法都不能被改变呢?答案是”是“,因为有 ...

  2. JavaScript检查是否包含某个字符

    转自:http://my.oschina.net/u/1450300/blog/389325 indexOf用法: indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置.如 ...

  3. Set的非重复判断是根据什么判断的

    HashSet 首先来看下HashSet的add()这个方法的源代码: public boolean add(E e) { return map.put(e, PRESENT)==null; } 由此 ...

  4. Mariadb-lib

    mariadb-libs-5.5.44-2.el7.centos.x86_64

  5. js产生随机数教程

    <script>   function GetRandomNum(Min,Max){   var Range = Max - Min;   var Rand = Math.random() ...

  6. MySQL数据库笔记总结

    MySQL数据库总结 一.数据库简介 1. 数据 所谓数据(Data)是指对客观事物进行描述并可以鉴别的符号,这些符号是可识别的.抽象的.它不仅仅指狭义上的数字,而是有多种表现形式:字母.文字.文本. ...

  7. MyBatis分页组件--PageHelper

    一.介绍 PageHelper是国内非常优秀的一款开源的 mybatis 分页插件,它支持基本主流与常用的数据库,例如 Oracle.Mysql.MariaDB.SQLite.Hsqldb 等. 官网 ...

  8. 如何用putty链接服务器端,并安装wdcp

    首先把自己阿里云的磁盘格式化然后重启 自己下载一个PuTTY 打开后输入自己的Ip地址端口号默认是22 会跳出一个yes 跟no界面,点击yes 会进入一个类似cmd界面 直接输入root,然后会提示 ...

  9. CSS——tab导航demo

    问题总结: 1.ul要比外套div宽度的值大一点 2.ul需要往左移动1px 3.外套的div设置overflow隐藏 解决抖动: 1.li宽度设置98px,padding左右值1px,hover之后 ...

  10. Python语言之模块

    模块基本上就是一个包含了所有你定义的函数和变量的文件.它用处在于使你你能在别的程序中重用它提供的功能和服务. 1.模块的使用方法 模块的文件名必须以.py作为扩展名. 当我们需要使用某个模块时,我们需 ...