Codeforces_807
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的更多相关文章
随机推荐
- shell正则表达式和cut命令
正则表达式 符号 描述 $ 匹配输入字符串的结尾位置 () 标记一个子表达式的开始和结束位置 * 匹配前面的子表达式零次或多次 + 匹配前面的子表达式一次或多次 . 匹配除换行符(\n)之外的任何单字 ...
- spring之整合Hibernate
spring整合Hibernate整合什么? 1.让IOC容器来管理Hibernate的SessionFactory. 2.让Hibernate使用上spring的声明式事务. 整合步骤: 1.加入H ...
- Java添加、读取Excel公式
操作excel表格用公式来处理数据时,可通过创建公式来运算数据,或通过读取公式来获取数据信息来源.本文以通过Java代码来演示在Excel中创建及读取公式的方法.这里使用了Excel Java类库(F ...
- Linux学习_菜鸟教程_3
我是在UBANTO上运行Linux的,开机启动时按下shift或者Esc都不能进入到grub,没有百度到可靠的教程. 暂时先这样吧.免得我把系统搞坏了,先学点实用的知识~~ Next Chapter
- 《C++Primer》第五版习题解答--第四章【学习笔记】
[C++Primer]第五版习题解答--第四章[学习笔记] ps:答案是个人在学习过程中书写,可能存在错漏之处,仅作参考. 作者:cosefy Date: 2020/1/11 第四章:表达式 练习4. ...
- 基于Spring封装的Javamail实现邮件发送
1.依赖 <dependency> <groupId>org.springframework</groupId> <artifactId>spring- ...
- .net Core 使用IHttpClientFactory请求
导读:本文已添加在晨曦微服务之旅,现在自己在尝试微服务架构,一边学边做项目快速的进入状态.当然在学习的过程中会将自己学到的知识进行分享. 一.为什么不用HttpClient ...
- JavaWeb系统(增删改查、多条件查询功能)
该系统是一个简单的青年服务管理系统,主要包括了较完整的常用的增删改查以及多条件查询功能,对于初学者有很大帮助. 下面是相关的Java代码.jsp页面.以及数据库的创建和相关表的设计 java代码 首先 ...
- oa办公系统是什么?对企业有什么作用?
OA办公系统是指利用计算机网络帮助企业实现办公自动化,用系统软件代替传统的手工工作帮助企业处理内部事务,例如文档共享.部门协作.报销.业务流程等等,最终目的帮助企业提高工作效率,实现利益最大化. 随着 ...
- 美食家App开发日记3
由于个人原因,感觉Android的学习特别复杂,初次接触,实在难以完成最初设想,所以将最初的设想做减法. 今天学习了ListView控件,将图片和美食名字使用ListView界面显示出来,并学习提升L ...