题目

1. 栈
    #A 表达式的转换 (Unaccepted)

2. STL 模板库

#B 双栈排序(Unaccepted)
    #C 垃圾陷阱(Accepted)
    #D 合并果子(Accepted)
    #E 统计数字(Unaccepted)
    #F 小木棍 [数据加强版](Unaccepted)

3. 树状数组

4. 归并排序

#H 逆序对(Unaccepted)

5. 最大子矩形

#A 最大正方形(Unaccepted)
    #B 奶牛浴场(Accepted)
    #C 最大加权矩形(Unaccepted)
    #D [ZJOI2007]棋盘制作 (Unaccepted)


1.  棋盘问题

/* Luogu P1549 棋盘问题(2)
* Au: GG
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
const int N = ;
int n, m, d[N][N];
bool numlist[N * N]; bool isprime(int x) {
int sq = sqrt(x);
for (int i = ; i <= sq; i++)
if (x % i == ) return false;
return true;
} bool dfs(int x, int y, int num) {
if (x > )
if (!isprime(num + d[x - ][y])) return false;
if (y > )
if (!isprime(num + d[x][y - ])) return false;
d[x][y] = num; numlist[num] = true;
if (x == n && y == n) return true;
int ax = x, ay = y;
if (ay == n) ay = , ax++; else ay++;
for (int i = ; i <= n * n; i++)
if (!numlist[i])
if (dfs(ax, ay, i)) return true;
numlist[num] = false;
return false;
} int main() {
scanf("%d", &n);
if (n == ) { printf("NO\n"); return ; }
if (dfs(, , )) {
for (int i = ; i <= n; i++) {
for (int j = ; j <= n; j++) {
printf("%d", d[i][j]);
if (j < n) printf(" ");
}
printf("\n");
}
}
else printf("NO\n");
return ;
}

2. 斐波那契数列

/* Luogu P2626 斐波那契数列(升级版)
* Au: GG
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = ; const long long mod = 2147483648ll;
int n, fd[N], pd[N], ptop = ; int Fibonacci(int x) {
if (x == || x == ) return ;
if (fd[x]) return fd[x];
return fd[x] = ((long long) Fibonacci(x - ) + (long long) Fibonacci(x - )) % mod;
}
void PrimeFac(int x) {
int sq = sqrt(x);
for (int i = ; i <= sq; i++)
if (x % i == ) {
x /= i; pd[ptop] = i; ptop++;
while (x % i == ) {
pd[ptop] = i; ptop++;
x /= i;
}
}
if (x > ) pd[ptop] = x, ptop++;
} int main() {
scanf("%d", &n);
int fb = Fibonacci(n);
PrimeFac(fb);
printf("%d=", fb);
for (int i = ; i < ptop; i++) {
if (i > ) printf("*");
printf("%d", pd[i]);
}
printf("\n");
return ;
}

3. 树状数组

/* Fenwick Tree
* Au: GG
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = + ;
int n, m, d[N]; inline int lowbit(int x) {
return x & (-x);
}
inline void modify(int x, int val) {
while (x <= n) {
d[x] += val; x += lowbit(x);
}
}
inline int getsum(int x) {
int sum = ;
while (x > ) {
sum += d[x]; x -= lowbit(x);
}
return sum;
} int main() {
scanf("%d%d", &n, &m);
for (int i = , w; i <= n; i++) {
scanf("%d", &w); modify(i, w);
}
while (m--) {
int o, x, y;
scanf("%d%d%d", &o, &x, &y);
if (o == ) modify(x, y);
if (o == ) printf("%d\n", getsum(y) - getsum(x - ));
}
return ;
}

4. 离散化

/* P2448 无尽的生命
* 树状数组 + 离散化
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int N = + ;
int n, m, a[ * N], b[ * N], h[ * N], cnt;
ll d[ * N], ans; struct ques {int x, y;} q[N]; int readint() {
int a = ; char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) {
a = a * + c - '';
c = getchar();
}
return a;
} int find(int x) {
int l = , r = m;
while (l <= r) {
int mid = (l + r) >> ;
if (h[mid] == x) return mid;
else if (h[mid] < x) l = mid + ;
else r = mid - ;
}
return r;
} inline int lowbit(int x) {
return x & (-x);
}
inline void modify(int x, int val) {
while (x <= m) {
d[x] += val; x += lowbit(x);
}
}
inline ll getsum(int x) {
ll sum = ;
while (x) {
sum += d[x];
x -= lowbit(x);
}
return sum;
} int main() {
n = readint();
for (int i = ; i <= n; i++) {
a[++cnt] = q[i].x = readint();
a[++cnt] = q[i].y = readint();
}
sort(a + , a + cnt + );
for (int i = ; i <= cnt; i++)
if (a[i] != a[i - ]) h[++m] = a[i]; for (int i = ; i <= m; i++) b[i] = i;
for (int i = ; i <= n; i++)
swap(b[find(q[i].x)], b[find(q[i].y)]); modify(b[m], );
for (int i = m - ; i; i--) {
ll o = h[i + ] - h[i] - ;
ll p = getsum(i);
ans += o * p;
modify(i, o);
ans += getsum(b[i] - );
modify(b[i], );
} printf("%lld\n", ans);
return ;
}
/* 火柴排队
* Au: GG
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; const int N = + ;
const int MOD = ; int n, c[N], d[N];
ll ans; struct node {
int num, pos;
bool operator < (const node &x) const {
return num < x.num;
}
} a[N], b[N]; inline int lowbit(int x) {
return x & (-x);
}
inline void modify(int x, int val) {
while (x <= n) {
d[x] += val; x += lowbit(x);
}
}
inline ll query(int x) {
ll sum = ;
while (x) {
sum += d[x]; x -= lowbit(x);
}
return sum;
} int main() {
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d", &a[i].num), a[i].pos = i;
for (int i = ; i <= n; i++)
scanf("%d", &b[i].num), b[i].pos = i;
sort(a + , a + n + );
sort(b + , b + n + );
for (int i = ; i <= n; i++)
c[b[i].pos] = a[i].pos;
for (int i = ; i <= n; i++) {
modify(c[i], );
ans = (ans + i - query(c[i])) % MOD;
}
printf("%lld\n", ans);
return ;
}

5. 快速幂

/* P1226 取余运算||快速幂
* Au: GG
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n, m, mod; ll quickpow(int a, int b) {
ll k = a, tot = ;
while (b) {
if (b & == ) tot = tot * k % mod;
k = k * k % mod;
b >>= ;
}
return tot;
} int main() {
scanf("%d%d%d", &n, &m, &mod);
printf("%d^%d mod %d=%lld\n", n, m, mod, quickpow(n, m));
return ;
}

6. 归并排序 (Unaccepted)

7. 二分

/* P2678 跳石头
* Au: GG
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = + ;
int L, n, m, dis[N], ans; bool judge(int x) {
int last = , cnt = ;
for (int i = ; i <= n + ; i++) {
if (dis[i] - dis[last] < x) cnt++;
else last = i;
}
if (cnt > m) return false;
return true;
} int main() {
scanf("%d%d%d", &L, &n, &m);
for (int i = ; i <= n; i++)
scanf("%d", &dis[i]);
dis[n + ] = L; int l = , r = L, mid;
while (l <= r) {
mid = (l + r) >> ;
if (judge(mid)) l = mid + , ans = mid;
else r = mid - ;
}
printf("%d\n", ans);
return ;
}
/* P1462 通往奥格瑞玛的道路
* Au: GG
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int N = + , M = + ;
int n, m; ll d[N];
ll blood, f[N], w[M * ], bin[N];
bool inq[N];
int head[N], nex[M * ], to[M * ], en;
queue<int> q; void add(int x, int y, int z) {
nex[++en] = head[x]; head[x] = en; to[en] = y; w[en] = z;
nex[++en] = head[y]; head[y] = en; to[en] = x; w[en] = z;
} bool judge(int fn) {
memset(d, 0x7f, sizeof(d));
memset(inq, false, sizeof(inq));
for (int i = ; i <= n; i++)
if (f[i] > fn) inq[i] = true;
if (f[] > fn || f[n] > fn) return false; q.push(); d[] = ; inq[] = true; while (!q.empty()) {
int a = q.front(); q.pop();
inq[a] = false;
for (int b = head[a]; b; b = nex[b])
if (d[a] + w[b] < d[to[b]]) {
d[to[b]] = d[a] + w[b];
if (!inq[to[b]]) {
q.push(to[b]);
inq[to[b]] = true;
}
}
}
return d[n] <= blood;
} int main() {
int a, b; ll c;
scanf("%d%d%lld", &n, &m, &blood);
for (int i = ; i <= n; i++) {
scanf("%lld", &f[i]);
bin[i] = f[i];
}
for (int i = ; i <= m; i++) {
scanf("%d%d%lld", &a, &b, &c);
add(a, b, c);
} sort(bin + , bin + n + ); int l = , r = n, mid;
while (l < r) {
mid = (l + r) >> ;
if (judge(bin[mid])) r = mid;
else l = mid + ;
}
if (l == r && !judge(bin[l])) printf("AFK\n");
else printf("%d\n", bin[l]);
return ;
}

杂项 List的更多相关文章

  1. 杂项之python描述符协议

    杂项之python描述符协议 本节内容 由来 描述符协议概念 类的静态方法及类方法实现原理 类作为装饰器使用 1. 由来 闲来无事去看了看django中的内置分页方法,发现里面用到了类作为装饰器来使用 ...

  2. 杂项之使用qq邮箱发送邮件

    杂项之使用qq邮箱发送邮件 本节内容 特殊设置 测试代码 1. 特殊设置 之前QQ邮箱直接可以通过smtp协议发送邮件,不需要进行一些特殊的设置,但是最近使用QQ邮箱测试的时候发现以前使用的办法无法奏 ...

  3. 杂项之图像处理pillow

    杂项之图像处理pillow 本节内容 参考文献 生成验证码源码 一些小例子 1. 参考文献 http://pillow-cn.readthedocs.io/zh_CN/latest/ pillow中文 ...

  4. 杂项之pymysql连接池

    杂项之pymysql连接池 本节内容 本文的诞生 连接池及单例模式 多线程提升 协程提升 后记 1.本文的诞生 由于前几天接触了pymysql,在测试数据过程中,使用普通的pymysql插入100W条 ...

  5. linux驱动初探之杂项设备(控制两个GPIO口)

    关键字:linux驱动.杂项设备.GPIO 此驱动程序控制了外接的两个二极管,二极管是低电平有效. 上一篇博客中已经介绍了linux驱动程序的编写流程,这篇博客算是前一篇的提高篇,也是下一篇博客(JN ...

  6. Linux驱动设计——字符杂项设备

    杂项设备 linux里面的misc杂项设备是主设备号为10的驱动设备,misc设备其实也就是特殊的字符设备,可自动生成设备节点. 定义头文件<linux/miscdevice.h>   杂 ...

  7. Posix线程编程指南(5) 杂项

    在Posix线程规范中还有几个辅助函数难以归类,暂且称其为杂项函数,主要包括pthread_self().pthread_equal()和pthread_once()三个,另外还有一个LinuxThr ...

  8. ARM指令集----杂项指令

    ARM指令集可以分为6类,即是跳转指令,数据处理指令,程序状态传输指令,Load.Store指令,协处理器指令和异常中断指令 跳转指令: 在ARM中有两种方式可以实现程序的跳转,一种是跳转指令,另一种 ...

  9. BootStrap入门教程 (三) :可重用组件(按钮,导航,标签,徽章,排版,缩略图,提醒,进度条,杂项)

    上讲回顾:Bootstrap的基础CSS(Base CSS)提供了优雅,一致的多种基础Html页面要素,包括排版,表格,表单,按钮等,能够满足前端工程师的基本要素需求. Bootstrap作为完整的前 ...

  10. 第二篇:杂项之图像处理pillow

    杂项之图像处理pillow   杂项之图像处理pillow 本节内容 参考文献 生成验证码源码 一些小例子 1. 参考文献 http://pillow-cn.readthedocs.io/zh_CN/ ...

随机推荐

  1. 【ABAP系列】SAP ABAP 利用class创建客户/供应商主数据

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP ABAP 利用class创建 ...

  2. Spring003--Spring事务管理(mooc)

    Spring事务管理 一.事务回顾 1.1.什么是事务 事务指的是逻辑上的一组操作,这组操作要么全部成功,要么全部失败. 异常情况发生,需要保证:[1]张三将钱转出,李四收到钱.[2]张三钱未成功转出 ...

  3. oracle--多表联合查询sql92版

    sql92学习 -查询员工姓名,工作,薪资,部门名称 sql的联合查询(多表查询) --1.sql92标准 ----笛卡尔积:一件事情的完成需要很多步骤,而不同的步骤有很多种方式,完成这件事情的所有方 ...

  4. python基础-7模块,第三方模块安装方法,使用方法。sys.path os sys time datetime hashlib pickle json requests xml

    模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才 ...

  5. 剑指Offer编程题(Java实现)——数组中的重复数字

    题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度为 ...

  6. CodeForces.1174D.EhabandtheExpectedXORProblem(构造前缀异或和数组)

    题目链接 这道题比赛的时候没做出来,赛后补题的时候发现其实可以构造一个前缀异或和数组,然后根据初始化的第一个值进行填数,但是作为菜鸡的我虽然坚信自己的想法是正确的却想了很久也没有能够构造出来所谓的前缀 ...

  7. UVA-10462.Is There A Second Way Left(Kruskal+次小生成树)

    题目链接 本题大意:这道题用Kruskal较为容易 参考代码: #include <cstdio> #include <cstring> #include <vector ...

  8. ajax传文件用express的multer接住

    html部分: //input type设为file <input type="file" name="file" id="fileInputE ...

  9. 洛谷 P2024 [NOI2001]食物链(种类并查集,加权并查集)

    传送门 解题思路 加权并查集: 什么是加权并查集? 就是记录着每个节点到它的父亲的信息(权值等). 难点:在路径压缩和合并节点时把本节点到父亲的权值转化为到根节点的权值 怎么转化呢? 每道题都不一样Q ...

  10. 使用pdfobject.js实现在线浏览PDF

    1.pdfobject.js官网:https://pdfobject.com/ 2.在html文件中引入这个文件,以pdfobject.min.js为例 <script type="t ...