LOJ#3032. 「JOISC 2019 Day1」馕

处理出每个人把馕切成N段,每一段快乐度相同,我们选择第一个排在最前的人分给他的第一段,然后再在未选取的的人中选一个第二个排在最前的切一下,并把第二段给他,这样下去一定有解

代码细节具体在比较大小的时候成绩可能需要int128

然后在给每个人分段的时候,把一个馕的长度当成\(Nq\),把要得到的每段长度当成\(sum\)(所有段快乐度的总和)就可以1去分了

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 2005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int64 gcd(int64 a,int64 b) {
return b == 0 ? a : gcd(b,a % b);
}
struct factor {
int64 x,y;
factor(int64 a = 0,int64 b = 1) {
x = a;y = b;
int64 g = gcd(x,y);x /= g;y /= g;
}
friend factor operator + (const factor &a,const factor &b) {
int64 u = a.x * b.y + b.x * a.y,d = a.y * b.y;
int64 g = gcd(u,d);u /= g;d /= g;
return factor(u,d);
}
friend factor operator - (const factor &a,const factor &b) {
int64 u = a.x * b.y - a.y * b.x;
int64 d = a.y * b.y;
int64 g = gcd(u,d);u /= g;d /= g;
return factor(u,d);
}
friend factor operator * (const factor &a,const factor &b) {
int64 u = a.x * b.x,d = a.y * b.y;
int64 g = gcd(u,d);
u /= g;d /= g;
return factor(u,d);
}
friend factor operator / (const factor &a,const factor &b) {
int64 u = a.x * b.y,d = a.y * b.x;
int64 g = gcd(u,d);u /= g;d /= g;
return factor(u,d);
}
friend bool operator < (const factor &a,const factor &b) {
return (__int128)a.x * b.y < (__int128)a.y * b.x;
}
friend bool operator == (const factor &a,const factor &b) {
return a.x * b.y == a.y * b.x;
}
friend bool operator <= (const factor &a,const factor &b) {
return a < b || a == b;
}
}cut[MAXN],poi[MAXN][MAXN];
int N,L,p[MAXN];
int64 rem[MAXN],v[MAXN][MAXN],sum[MAXN];
bool vis[MAXN];
void Solve() {
read(N);read(L);
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j <= L ; ++j) {
read(v[i][j]);
sum[i] = sum[i] + v[i][j];
}
}
for(int i = 1 ; i <= N ; ++i) {
int now = 1;
for(int j = 1 ; j <= L ; ++j) rem[j] = N * v[i][j];
for(int j = 1 ; j < N ; ++j) {
int64 sv = sum[i];
while(1) {
if(rem[now] < sv) {sv -= rem[now];++now;continue;}
else {
rem[now] -= sv;
poi[i][j] = now - factor(rem[now],N * v[i][now]);
break;
}
}
}
}
for(int j = 1 ; j < N ; ++j) {
int pos = -1;
for(int i = 1 ; i <= N ; ++i) {
if(!vis[i]) {
if(pos == -1) pos = i;
else if(poi[i][j] < poi[pos][j]) pos = i;
}
}
p[j] = pos;vis[pos] = 1;
out(poi[pos][j].x);space;out(poi[pos][j].y);enter;
}
for(int i = 1 ; i <= N ; ++i) {
if(!vis[i]) {p[N] = i;break;}
}
for(int i = 1 ; i <= N ; ++i) {
out(p[i]);space;
}
enter;
}
int main() {
#ifdef ivorysi
freopen("03-02.in","r",stdin);
#endif
Solve();
}

【LOJ】#3032. 「JOISC 2019 Day1」馕的更多相关文章

  1. 【LOJ】#3031. 「JOISC 2019 Day1」聚会

    LOJ#3031. 「JOISC 2019 Day1」聚会 听说随机可过? 我想了很久想了一个不会被卡的做法,建出前\(u - 1\)个点的虚树,然后找第\(u\)个点的插入位置,就是每次找一条最长链 ...

  2. 【LOJ】#3030. 「JOISC 2019 Day1」考试

    LOJ#3030. 「JOISC 2019 Day1」考试 看起来求一个奇怪图形(两条和坐标轴平行的线被切掉了一个角)内包括的点个数 too naive! 首先熟练的转化求不被这个图形包含的个数 -- ...

  3. @loj - 3039@ 「JOISC 2019 Day4」蛋糕拼接 3

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 今天是 IOI 酱的生日,所以她的哥哥 JOI 君给她预定了一个 ...

  4. 【LOJ】#3036. 「JOISC 2019 Day3」指定城市

    LOJ#3036. 「JOISC 2019 Day3」指定城市 一个点的可以dp出来 两个点也可以dp出来 后面的就是在两个点的情况下选一条最长的链加进去,用线段树维护即可 #include < ...

  5. 【LOJ】#3034. 「JOISC 2019 Day2」两道料理

    LOJ#3034. 「JOISC 2019 Day2」两道料理 找出最大的\(y_{i}\)使得\(sumA_{i} + sumB_{y_i} \leq S_{i}\) 和最大的\(x_{j}\)使得 ...

  6. 【LOJ】#3033. 「JOISC 2019 Day2」两个天线

    LOJ#3033. 「JOISC 2019 Day2」两个天线 用后面的天线更新前面的天线,线段树上存历史版本的最大值 也就是线段树需要维护历史版本的最大值,后面的天线的标记中最大的那个和最小的那个, ...

  7. 「JOISC 2019 Day3」穿越时空 Bitaro

    「JOISC 2019 Day3」穿越时空 Bitaro 题解: ​ 不会处理时间流逝,我去看了一眼题解的图,最重要的转换就是把(X,Y)改成(X,Y-X)这样就不会斜着走了. ​ 问题变成二维平面上 ...

  8. 「JOISC 2014 Day1」巴士走读

    「JOISC 2014 Day1」巴士走读 将询问离线下来. 从终点出发到起点. 由于在每个点(除了终点)的时间被过来的边固定,因此如果一个点不被新的边更新,是不会发生变化的. 因此可以按照时间顺序, ...

  9. 「JOISC 2014 Day1」 历史研究

    「JOISC 2014 Day1」 历史研究 Solution 子任务2 暴力,用\(cnt\)记录每种权值出现次数. 子任务3 这不是一个尺取吗... 然后用multiset维护当前的区间,动态加, ...

随机推荐

  1. mov 与 lea 区别

    转自:https://blog.csdn.net/fengyuanye/article/details/85715565 https://my.oschina.net/guonaihong/blog/ ...

  2. Django基础之cookie

    1. Cookie 1.1 Cookie的由来 大家都知道HTTP协议是无状态的.无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系, 它不会受前面的请求响应情况 ...

  3. python国内镜像源

    让python pip使用国内镜像 国内源: 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pyp ...

  4. javascript数组的增删改和查询

    数组的增删改操作 对数组的增删改操作进行总结,下面(一,二,三)是对数组的增加,修改,删除操作都会改变原来的数组. (一)增加 向末尾增加 push() 返回新增后的数组长度 arr[arr.leng ...

  5. Beta冲刺(1/5)

    队名:new game 组长博客:戳 作业博客:戳 组员情况 鲍子涵(队长) 过去两天完成了哪些任务 验收游戏素材 学习Unity 2D Animation系统 接下来的计划 制作游戏需要的人物动画 ...

  6. linux基础技巧

    命令行颜色显示: \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\0 ...

  7. Django admin site应用

    django自带的admin后台管理,可以实现对数据库表的增删改查,用起来十分方便.其使用和配置主要分为三个步骤: 1,创建超级用户 需要创建超级用户来登陆admin后台系统,在命令行中输入 pyth ...

  8. linux下如何将dts转换成dtb?

    答: 使用dtc工具,如: <kernel source code dir>/scripts/dtc/dtc -I dts -O dtb -o <dtb filename> & ...

  9. eclipse syso 自动补全设置方法

    eclipse syso 自动补全设置方法   转  https://blog.csdn.net/sinat_23536373/article/details/76512390   经常遇到打”sys ...

  10. C#Application:Exit与ExitThread 解释

    Application.Exit(); 方法停止在所有线程上运行的所有消息循环,并关闭应用程序的所有窗口 Application.ExitThread 方法 退出当前线程上的消息循环,并关闭该线程上的 ...