A. 严格按照题目给的两个条件来。

#include<bits/stdc++.h>
using namespace std; int n,a[],b[]; int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i] >> b[i];
int flag1 = ,flag2 = ;
for(int i = ;i <= n;i++)
{
if(a[i] != b[i]) flag1 = ;
}
for(int i = ;i < n;i++)
{
if(a[i] < a[i+]) flag2 = ;
}
if(flag1) cout << "rated" <<endl;
else if(flag2) cout << "unrated" << endl;
else cout << "maybe" << endl;
return ;
}

B.可能的值为xx = x+50k(xx >= y),从小到大枚举每一个可能的值,计算cnt就可以了。

#include<bits/stdc++.h>
using namespace std; int x,y,p,a[]; int main()
{
ios::sync_with_stdio(false);
cin >> p >> x >> y;
int xx = x;
while(x >= y)
{
int t = x/%;
for(int i = ;i <= ;i++)
{
t = (t*+)%;
a[i] = t+;
if(a[i] == p)
{
cout << << endl;
return ;
}
}
x -= ;
}
x = xx;
int cnt = ,now = ;
while()
{
int t = x/%;
for(int i = ;i <= ;i++)
{
t = (t*+)%;
a[i] = t+;
if(a[i] == p)
{
cout << cnt << endl;
return ;
}
}
x += ;
now++;
if(now == )
{
now = ;
cnt++;
}
}
return ;
}

C.先判断0和-1的情况,然后按大小分类。

若x/y < p/q,我们要把x/y变得尽量大,并且最后的值是p/q,可以变成(np-(y-x))/nq,计算n向上取整,然后结果为nq-y。

若x/y > p/q,我们要把x/y变得尽量小,即只加分母,不加分子,最后变成x/nq == np/nq,计算n向上取整,结果同上。

#include<bits/stdc++.h>
using namespace std; long long x,y,xx,yy; int main()
{
ios::sync_with_stdio(false);
int T;
cin >> T;
while(T--)
{
cin >> x >> y >> xx >> yy;
if(x*yy == y*xx)
{
cout << << endl;
continue;
}
if(x != && xx == || xx >= yy)
{
cout << - << endl;
continue;
}
if(x*yy < xx*y)
{
long long t = y-x;
long long ans = t/(yy-xx);
if(ans*yy-t < ans*xx) ans++;
cout << ans*yy-y << endl;
}
else
{
long long ans = x/xx;
if(ans*xx < x) ans++;
cout << ans*yy-y << endl;
}
}
return ;
}

还可以二分n值来写。


D.暴力枚举到100000就可以了。

#include<bits/stdc++.h>
using namespace std; int n,a[][],b[] = {},c[]; int calc(int x,int y,int z)
{
int t = -x;
if(x == -) return ;
if(*y > z) return *t;
if(*y > z) return *t;
if(*y > z) return *t;
if(*y > z) return *t;
if(*y > z) return *t;
return *t;
} bool ok(int x)
{
int sum1 = ,sum2 = ;
for(int i = ;i <= ;i++) c[i] = b[i];
for(int i = ;i <= ;i++)
{
if(a[][i] != - && a[][i] > a[][i]) c[i] += x;
}
for(int i = ;i <= ;i++)
{
sum1 += calc(a[][i],c[i],n+x);
sum2 += calc(a[][i],c[i],n+x);
}
return sum1 > sum2;
}
int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = ;i <= n;i++)
{
for(int j = ;j <= ;j++)
{
cin >> a[i][j];
if(a[i][j] >= ) b[j]++;
}
}
for(int i = ;i <= ;i++)
{
if(ok(i))
{
cout << i << endl;
return ;
}
}
cout << - << endl;
return ;
}

E.分别对2的倍数,与2倍数间隔间的数计数,结果个数最多为1的个数,对每个个数,我们判断其是否可行。

我们贪心当前2的倍数之后一个的2的倍数,使剩下来的2的倍数的数量和非2倍数数量和尽可能少,因为剩下的个数为最小的划分的数的个数。

#include<bits/stdc++.h>
using namespace std; int n,now = ,num[] = {},two[] = {},ans[]; bool ok(int x)
{
int t = two[]-x;
for(int i = ;i <= now;i++)
{
if(x >= two[i])
{
t -= min(x-two[i],t);
x = two[i];
}
else t += two[i]-x;
t += num[i];
}
if(t <= x) return ;
return ;
} int main()
{
ios::sync_with_stdio(false);
cin >> n;
long long t = ;
for(int i = ;i <= n;i++)
{
long long x;
cin >> x;
if(x == t) two[now]++;
else if(x < t) num[now-]++;
else
{
while(t < x)
{
t *= ;
now++;
}
if(x == t) two[now]++;
else num[now-]++;
}
}
int cnt = ;
for(int i = ;i <= two[];i++)
{
if(ok(i)) ans[++cnt] = i;
}
if(cnt == ) cout << - << endl;
else
{
for(int i = ;i <= cnt;i++) cout << ans[i] << " ";
cout << endl;
}
return ;
}

F.首先一种特殊情况,我们选择权值最小(w0)的一条边,设其两点为A,B,不难理解,A,B两点的总p值均为(n-1)*w0。

然后,对于其他的点,取点a,每个点连接着(n-1)条边,对于每条边,权值为w1,设它连的点为a,b,那么,我们可以把除a,b外的所有点先连成最小,即所有边最终跑向A或B,即(n-3)*w0,然后连接A到b或者B到b,再b到a,这里最后两条路径的权值分为两种情况:①若前一点->b 大于 b->a,则总p值为(n-3)*w0+2*w1

②若前一点->b 小于 b->a,则总p值为(n-3)*w0+w前一点->b+w1

这样的情况下,我们在(n-1)*2种情况里取的最小p值为最优解。

第一种情况比较好求解,第二种情况我们可以从到b点的最优转换而来,把原来的a去掉,在最后加上b->a,即-minn+w1。

这样我们就对求解顺序有一定的要求,按边权值从小到大排序,每次更新边的两个点,是符合要求的。

#include<bits/stdc++.h>
using namespace std; int n;
long long ans[];
struct xx
{
int u,v,w;
xx(int a,int b,int c):u(a),v(b),w(c){};
friend bool operator <(xx a,xx b)
{
return a.w < b.w;
}
}; vector<xx> v; int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = ;i <= n;i++) ans[i] = 1e18;
for(int i = ;i <= n;i++)
{
for(int j = i+;j <= n;j++)
{
int x;
cin >> x;
v.push_back(xx(i,j,x));
}
}
sort(v.begin(),v.end());
long long minn = v[].w;
for(int i = ;i < v.size();i++)
{
int x = v[i].u,y = v[i].v,w = v[i].w;
long long t = (long long)w*+minn*(n-);
ans[x] = min(ans[x],min(ans[y]-minn+w,t));
ans[y] = min(ans[y],min(ans[x]-minn+w,t));
}
for(int i = ;i <= n;i++) cout << ans[i] << endl;
return ;
}

Codeforces_807的更多相关文章

随机推荐

  1. Win10下设置默认输入法与默认中文输入

    实现的效果: 把自己需要的一个或多个输入法软件添加到输入法列表中(一般就指定一个),避免了需要在打字时Ctrl + Shift等快捷键在多个输入法中不停切换的麻烦 首选语言默认为中文,毕竟作为一个中国 ...

  2. 用户svn密码自定义

    由于在linux系统Apache+svn服务器,用户需要自定义密码怎么办呢? 1.创建脚本目录 mkdir -p /var/www/svn/svntools 2.创建apache配置文件 touch ...

  3. windebug(转载别人的节选)

    问题一:WinDBG分X86和X64两个版本 如果你用的是32位的WinDBG,那直接打开就行:你如果用的是64位的版本,那么如果调试64位代码也直接打开,如果调试x86的代码,要使用Wow64下的W ...

  4. Arrays.asList() 导致的java.lang.UnsupportedOperationException异常

    Arrays.asList() 只支持遍历和取值 不支持增删改 继承至AbstractList内部类

  5. Intellij Idea插件使用记录之Alibaba Java Coding Guidelines

    目录 Intellij Idea插件Alibaba Java Coding Guidelines 前言 使用 感谢 Intellij Idea插件Alibaba Java Coding Guideli ...

  6. Linux学习_菜鸟教程_1

    Linux系统启动过程:内核的引导 .运行init.系统初始化.建立终端.用户登录系统 内核引导:计算机开机,然后BIOS开机自检,按照BIOS中设置的启动设备(通常是硬盘)来启动. 操作系统接管硬件 ...

  7. 如何制作地图故事使用esri story maps

    博客作者原创 制作方法如下:http://url.cn/5dnsVQd

  8. python线性数据结构

    1.栈(Stack)(后进先出) 栈的实现: class Stack: def __init__(self): self.items = [] def isEmpty(self): return se ...

  9. 安装k8s和NVIDIA环境

    安装环境 系统要求 CPU: 2个核心 内存: 2GB 显卡:NVIDIA系列 安装docker apt install docker.io 安装k8s 添加软件源 方便起见,将Ubuntu的软件管理 ...

  10. 在 Vue 中使用 Typescript

    前言 恕我直言,用 Typescript 写 Vue 真的很难受,Vue 对 ts 的支持一般,如非万不得已还是别在 Vue 里边用吧,不过听说 Vue3 会增强对 ts 的支持,正式登场之前还是期待 ...