T1:math

题目链接:

http://zhengruioi.com/contest/156/problem/471

题解:

先讲讲我的乱搞做法。对于前面70%,我跑了背包。因为背包有后效性...我做了两次,也就是迭代了一下

剩下的30%随机化了一波。就是先把每个数的20以内的倍数暴力的算出来对k取模然后丢到一个大小为k的桶里面去。因为题目就是让你给每个数一个系数,于是我就每次随机两个位置相加判断在模k的意义下是否出现过,如果没有出现过就加入答案中,咳咳重复1e7次即可A掉本题

下面说说题解做法:

$ax+by=z$存在整数解,当且仅当$gcd(a, b)∣z$。

那么,若z可以被凑出,即 $\sum_{i=1}^{n} x_ia_i = z$,当且仅当 $gcd(a_1, a_2,⋯, a_n)∣z$。

因此,答案只能是gcd的整数倍。

但是,这样考虑x有可能是负数,但是在mod k的条件下,我们可以把x调为非负整数。

时间复杂度$O((n + k)logv)$。

乱搞代码

#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<time.h>
using namespace std; const int N=1e6+;
int n,k;
int a[N],f[N];
inline int read(){
char ch=getchar();int s=,f=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<='') {s=(s<<)+(s<<)+ch-'';ch=getchar();}
return s*f;
}
namespace task1
{
void main()
{
for (int i=;i<=n;i++)
for (int j=;!f[1ll*j*a[i]%k];j++) f[1ll*j*a[i]%k]=;
for (int i=;i<=n;i++)
{
for (int j=;j<=k;j++) f[j]|=f[((j-a[i])%k+k)%k];
for (int j=;j<=k;j++) f[j]|=f[((j-a[i])%k+k)%k];
}
int s=;
for (int j=;j<k;j++) s+=f[j];
printf("%d\n",s);
for (int j=;j<k;j++) if (f[j]) printf("%d ",j);
}
}
int gcd(int a,int b) {if (!b) return a;else return gcd(b,a%b);}
namespace task2
{
void main()
{
printf("%d\n",k);
for (int i=;i<k;i++) printf("%d ",i);
}
}
int main()
{
n=read();k=read();
for (int i=;i<=n;i++) a[i]=read()%k;
for (int i=;i<=n;i++) if (a[i]==||gcd(a[i],k)==) {task2::main();return ;}
if (n<=) {task1::main();return ;}
srand(time());
vector <int> p;
for (int i=;i<=n;i++)
{
for (int j=;j<=;j++)
{
int q=1ll*j*a[i]%k;
if (!f[q])
{
p.push_back(q);
f[q]=;
}
}
}
for (int i=;i<=1e7;i++)
{
int si=p.size();
int l=rand()%si,r=rand()%si;
if (!f[(p[l]+p[r])%k])
{
p.push_back((p[l]+p[r])%k);
f[(p[l]+p[r])%k]=;
}
}
int s=;
for (int j=;j<k;j++) s+=f[j];
printf("%d\n",s);
for (int j=;j<k;j++) if (f[j]) printf("%d ",j);
return ;
}

T2:biology

题目链接:

http://zhengruioi.com/contest/156/problem/472

题解:

我们显然可以把元素按$a$排序,然后宽搜转移。

$f_{x,y}$ 表示当前路径的结尾在$(x,y)$位置的最大吸引度之和。 $f_{x,y} = b_{x,y}+max (f_{z,k} + ∣x −z ∣ + ∣y −k∣, a_{x,y} >a_{z,k} )$

暴力转移时间复杂度最差为$O(n ^2 m^2)$,考虑优化。

坐标转化$(x,y)->(x+y,x-y)$

这样原来的曼哈顿距离$|x-z|+|y-k|$就变成了切比雪夫距离$max(|x-z|,|y-k|)=max(x-z,z-x,y-k,k-y)$

这样坐标是最大值,转移也是最大值,因此可以用4个变量分别记录最大的$f_{z,k}-z,f_{z,k}+z,f_{z,k}-k,f_{z,k}+k$

时间复杂度为排序复杂度$O(nmlognm)$

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll; const int N=2e3+;
const ll inf=1e9;
int n,m,tot;
ll A,B,C,D;
ll b[N][N],dp[N][N];
inline ll read(){
char ch=getchar();ll s=,f=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<='') {s=(s<<)+(s<<)+ch-'';ch=getchar();}
return s*f;
}
struct node{
int x,y;
int d;
}s[N*N];
bool operator < (node x,node y) {return x.d<y.d;}
void chkmx(ll &a,ll b) {if (b>a) a=b;}
void calc()
{
int l=;ll mx=;
A=-inf;B=-inf;C=-inf;D=-inf;
while (l<=tot)
{
int r=l;
while (r<tot&&s[r].d==s[r+].d) ++r;
for (int k=l;k<=r;k++)
{
int x=s[k].x,y=s[k].y;
int i=x+y,j=x-y;
dp[x][y]=b[x][y];
chkmx(dp[x][y],b[x][y]+A+i);
chkmx(dp[x][y],b[x][y]+B-i);
chkmx(dp[x][y],b[x][y]+C+j);
chkmx(dp[x][y],b[x][y]+D-j);
chkmx(mx,dp[x][y]);
}
for (int k=l;k<=r;k++)
{
int x=s[k].x,y=s[k].y;
int i=x+y,j=x-y;
chkmx(A,dp[x][y]-i);
chkmx(B,dp[x][y]+i);
chkmx(C,dp[x][y]-j);
chkmx(D,dp[x][y]+j);
}
l=r+;
}
printf("%lld\n",mx);
}
int main()
{
n=read();m=read();
for (int i=;i<=n;i++)
for (int j=,x;j<=m;j++)
{
x=read();
if (x) s[++tot]=(node){i,j,x};
}
for (int i=;i<=n;i++)
for (int j=;j<=m;j++) b[i][j]=read();
sort(s+,s++tot);
calc();
return ;
}

正睿NOIP赠送附加赛1的更多相关文章

  1. 10.25 正睿停课训练 Day9

    目录 2018.10.25 正睿停课训练 Day9 A 数独(思路 DP) B 红绿灯(最短路Dijkstra) C 轰炸(计算几何 圆并) 考试代码 B C 2018.10.25 正睿停课训练 Da ...

  2. 11.6 正睿停课训练 Day17

    目录 2018.11.6 正睿停课训练 Day17 A chinese(思路 计数) B physics(单调队列/剪枝 DP) C chemistry(期望 DP) 考试代码 A B C 2018. ...

  3. 8.10 正睿暑期集训营 Day7

    目录 2018.8.10 正睿暑期集训营 Day7 总结 A 花园(思路) B 归来(Tarjan 拓扑) C 机场(凸函数 点分治) 考试代码 A B C 2018.8.10 正睿暑期集训营 Day ...

  4. 10.31 正睿停课训练 Day13

    目录 2018.10.31 正睿停课训练 Day13 A Poker(期望) B Label(高斯消元) C Coin(二分图染色 博弈) 考试代码 A(打表) B 2018.10.31 正睿停课训练 ...

  5. 11.5 正睿停课训练 Day16

    目录 2018.11.5 正睿停课训练 Day16 A 道路规划(思路) B 逻辑判断(枚举 位运算/DP 高维前缀和) C 区间(贪心/树状数组) 考试代码 A B C 2018.11.5 正睿停课 ...

  6. 11.2 正睿停课训练 Day15

    目录 2018.11.2 正睿停课训练 Day15 A 郁闷的小G(二分) B 小G的树(树形DP) C 数的距离(思路) 考试代码 B C 2018.11.2 正睿停课训练 Day15 时间:3.5 ...

  7. 11.1 正睿停课训练 Day14

    目录 2018.11.1 正睿停课训练 Day14 A 字符串 B 取数游戏(贪心) C 魔方(模拟) 考试代码 B C 2018.11.1 正睿停课训练 Day14 时间:3.5h 期望得分:100 ...

  8. 10.29 正睿停课训练 Day11

    目录 2018.10.29 正睿停课训练 Day11 A 线段树什么的最讨厌了(思路 DFS) B 已经没有什么好害怕的了(差分 前缀和) C 我才不是萝莉控呢(DP 贪心 哈夫曼树) 考试代码 A ...

  9. 10.30 正睿停课训练 Day12

    目录 2018.10.30 正睿停课训练 Day12 A 强军战歌(DP 树状数组 容斥) B 当那一天来临(思路) C 假如战争今天爆发(贪心) 考试代码 B C 2018.10.30 正睿停课训练 ...

随机推荐

  1. bzoj1786: [Ahoi2008]Pair 配对&&1831: [AHOI2008]逆序对

    一个自以为很对的东西,我们往-1放的数肯定是不增的. 然后就预处理一下,假如i这个位置放j会多多少逆序对. DP一下,我的复杂度应该是O(n*m^2)的,然而你随便搞都能省掉一个m吧,我算了算好像可以 ...

  2. bzoj3713: [PA2014]Iloczyn(乱搞)

    3713: [PA2014]Iloczyn 题目:传送门 题解: 随手一发水题x2 直接离线啊,斐波那契到了第五十个就炒鸡大了 代码: #include<cstdio> #include& ...

  3. zzulioj--1613--少活一年?(稍微有点坑,水!)

    1613: 少活一年? Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 344  Solved: 70 SubmitStatusWeb Board De ...

  4. WebService CXF学习:复杂对象传递(List,Map)

    转自:https://blog.csdn.net/z69183787/article/details/35988335 第一步:创建存储复杂对象的类(因为WebServices的复杂对象的传递,一定要 ...

  5. php的异步并行扩展swoole

    Swoole是PHP的异步并行扩展,有点像Node.js,但swoole既支持同步又支持异步,比node更强大.Swoole扩展是基于epoll高性能事件轮询,并且是多线程的,性能非常好. Swool ...

  6. 计算机基础--http的基础整理和巩固

    一.前言 主要包括:1.http基础:TCP/IP,TCP协议,IP协议,DNS协议,URI与URL: 2.http协议:http报文,http方法,http状态码,常见问题 名词解释: (1)HTT ...

  7. python包管理(distutils、easy_install、pip、setup.py/requirements.txt、wheel)

    distutils.distutils2 distutils是 python 标准库的一部分,2000年发布.使用它能够进行 python 模块的 安装 和 发布. distutils2 被设计为 d ...

  8. SQL Server的复合索引学习【转载】

      概要什么是单一索引,什么又是复合索引呢? 何时新建复合索引,复合索引又需要注意些什么呢?本篇文章主要是对网上一些讨论的总结. 一.概念 单一索引是指索引列为一列的情况,即新建索引的语句只实施在一列 ...

  9. 路飞学城Python-Day31

    19-生产者消费者模型 生产者:生成数据的任务 消费者:处理数据的任务 在并发编程的过程中,如果生产者处理速度很快,而消费者处理速度很慢,那么生产者就必须等待消费者处理,才能继续生产数据:同样的,如果 ...

  10. Pyhton学习——Day25

    #面向对象的几个方法#1.静态方法@staticmethod,不能访问类属性,也不能访问实例属性,只是类的工具包#2.类方法:@classmethod,在函数属性前加上类方法,显示为(cls)代表类, ...