Codeforces Round #499 (Div. 2)
Codeforces Round #499 (Div. 2)
https://codeforces.com/contest/1011
A
#include <bits/stdc++.h>
using namespace std;
int n,k,i,j,p,r,a[];
string s;
int main(){
for(cin>>n>>k>>s;i<n;i++)a[i]=s[i]-'a'+;
sort(a,a+n);
for(i=,p=-;i<n&&j<k;i++){
if(p+<a[i])r+=a[i],j++,p=a[i];
}
cout<<(j==k?r:-);
}
B
#include <bits/stdc++.h>
using namespace std;
int n,m,k,i,x,t,l,r,c[];
int main(){
for(cin>>n>>m;i<m;i++)cin>>x,c[x]++;
for(l=,r=;(l+r)/>l;){
k=(l+r)/;
for(t=i=;i<;i++)t+=c[i]/k;
(t>=n?l:r)=k;
}
cout<<l;
}
C
模拟
题意:从地球飞到火星要经过n-2个星球,最后直接返回地球,每次起飞和降落都需要燃料,且效率不同。火箭重为m,星球数为n,火箭在星球上起飞和降落时的燃料效率ai和bi,求出发时需携带的最小燃料量,若不可行,输出-1。
思路:直接模拟即可
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 200005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int a[],b[]; int main(){
// std::ios::sync_with_stdio(false);
int n;
double s;
cin>>n>>s;
int flag=;
for(int i=;i<=n;i++){
cin>>a[i];
if(a[i]<=){
flag=;
}
}
for(int i=;i<=n;i++){
cin>>b[i];
if(b[i]<=){
flag=;
}
}
if(!flag){
cout<<-;
}
else{
double ans=;
for(int i=;i<=n;i++){
double tmp;
tmp=s/(a[i]-);
s+=tmp;
ans+=tmp;
tmp=s/(b[i]-);
s+=tmp;
ans+=tmp;
}
printf("%.7f\n",ans);
}
}
D
交互题
题意:系统想一个数,你来猜,猜的数比系统想的大,返回1,小则返回-1,猜对了返回0。特殊的是,该系统每隔k次询问会撒一次谎,输出猜对的过程(猜的次数不超过60)
思路:前k次询问先找到系统第一次说谎的时候,剩下的60-k次就二分猜就行
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 200005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int a[]; int main(){
std::ios::sync_with_stdio(false);
int n,m;
cin>>m>>n;
int x;
for(int i=;i<n;i++){
cout<<<<endl;
cin>>x;
if(x==) return ;
a[i]=x;
}
int L=,R=m,mid;
for(int i=n;i<;i++){
mid=L+R>>;
cout<<mid<<endl;
cin>>x;
if(x==) return ;
if(x*a[i%n]>){
L=mid+;
}
else{
R=mid-;
}
}
}
E
题意:有n种价值不同的钞票,每种有无数张。问在k进制下能凑出几种尾数不同的钞票
思路:gcd求最大公约数即可
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 200005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int main(){
std::ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
int a;
cin>>a;
int gcd=a;
for(int i=;i<=n;i++){
cin>>a;
gcd=__gcd(gcd,a);
if(gcd==) break;
}
gcd=__gcd(gcd,k);
int ans=k/gcd;
cout<<ans<<endl;
for(int i=;i<ans;i++){
cout<<gcd*i<<" ";
}
}
F
思维题
题意:给你一颗二叉树,父节点的值等于子节点的值通过“四则运算”得到(XOR,OR,AND,NOT),问每次改变一个叶子节点的值后,根节点的值为多少,每个操作之间互不影响
思路:先跑一遍dfs,求出根结点的值,第二次遍历的时候分类讨论,判断一个节点的值的改变对其父节点有没有影响。
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; vector<int>ve[maxn];
int n;
struct sair{
string str;
int v;
}a[maxn]; int val[maxn];
int ans[maxn];
int vis[maxn]; void dfs1(int pos){
int ans;
if(a[pos].str=="AND"){
for(int i=;i<ve[pos].size();i++){
dfs1(ve[pos][i]);
}
val[pos]=val[ve[pos][]]&val[ve[pos][]];
}
else if(a[pos].str=="IN"){
val[pos]=a[pos].v;
}
else if(a[pos].str=="XOR"){
for(int i=;i<ve[pos].size();i++){
dfs1(ve[pos][i]);
}
val[pos]=val[ve[pos][]]^val[ve[pos][]];
}
else if(a[pos].str=="NOT"){
dfs1(ve[pos][]);
val[pos]=!val[ve[pos][]];
}
else{
for(int i=;i<ve[pos].size();i++){
dfs1(ve[pos][i]);
}
val[pos]=val[ve[pos][]]|val[ve[pos][]];
}
} void dfs2(int pos){
int x,y;
// cout<<pos<<endl;
if(a[pos].str=="IN"){
ans[pos]=!val[];
}
else if(a[pos].str=="AND"){
x=val[ve[pos][]],y=val[ve[pos][]];
if(x==&&y==){
dfs2(ve[pos][]);
}
else if(x==&&y==){
dfs2(ve[pos][]);
}
else if(x==&&y==){
dfs2(ve[pos][]);
dfs2(ve[pos][]);
}
}
else if(a[pos].str=="OR"){
x=val[ve[pos][]],y=val[ve[pos][]];
if(x==&&y==){
dfs2(ve[pos][]);
}
else if(x==&&y==){
dfs2(ve[pos][]);
}
else if(x==&&y==){
dfs2(ve[pos][]);
dfs2(ve[pos][]);
}
}
else if(a[pos].str=="XOR"){
x=val[ve[pos][]],y=val[ve[pos][]];
if(x==&&y==){
dfs2(ve[pos][]);
dfs2(ve[pos][]);
}
else if(x==&&y==){
dfs2(ve[pos][]);
dfs2(ve[pos][]);
}
else if(x==&&y==){
dfs2(ve[pos][]);
dfs2(ve[pos][]);
}
else if(x==&&y==){
dfs2(ve[pos][]);
dfs2(ve[pos][]);
}
}
else if(a[pos].str=="NOT"){
x=val[ve[pos][]];
dfs2(ve[pos][]);
}
} int main(){
std::ios::sync_with_stdio(false);
cin>>n;
string str;
int x,y;
for(int i=;i<=n;i++){
cin>>str>>x;
a[i].str=str;
if(str=="AND"){
cin>>y;
ve[i].pb(x);
ve[i].pb(y);
a[i].v=;
}
else if(str=="IN"){
a[i].v=x;
}
else if(str=="XOR"){
cin>>y;
ve[i].pb(x);
ve[i].pb(y);
a[i].v=;
}
else if(str=="NOT"){
ve[i].pb(x);
a[i].v=;
}
else{
cin>>y;
ve[i].pb(x);
ve[i].pb(y);
a[i].v=;
}
}
dfs1();
for(int i=;i<=n;i++) ans[i]=val[];
dfs2();
for(int i=;i<=n;i++){
if(a[i].str=="IN"){
cout<<ans[i];
}
}
cout<<endl;
}
Codeforces Round #499 (Div. 2)的更多相关文章
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round #499 (Div. 1)
Codeforces Round #499 (Div. 1) https://codeforces.com/contest/1010 为啥我\(\rm Div.1\)能\(A4\)题还是\(\rm s ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- 7-27 Codeforces Round #499 (Div. 2)
C. Fly 链接:http://codeforces.com/group/1EzrFFyOc0/contest/1011/problem/C 题型:binary search .math. 题意:总 ...
- Codeforces Round #499 (Div. 2) D. Rocket题解
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
- Codeforces Round #499 (Div. 2) C Fly题解
题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...
- Codeforces Round #499 (Div. 2) Problem-A-Stages(水题纠错)
CF链接 http://codeforces.com/contest/1011/problem/A Natasha is going to fly to Mars. She needs to bui ...
- Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)
C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces Round #499 (Div. 2)(1011)
Natasha is planning an expedition to Mars for nn people. One of the important tasks is to provide fo ...
随机推荐
- matplotlib.pyplot展示MNIST图片
import torch import torch.utils.data as Data import torchvision import torchvision.transforms as tra ...
- eclipse中,将springboot项目打成jar包
1.右击项目,选择Run As - Maven clean 2.右击项目,选择Run As - Maven install 3.成功后 会在项目的target文件夹下生成jar包 4.将打包好的jar ...
- 项目期复习:JS操作符,弹窗与调试,凝视,数据类型转换
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/huangyibin628/article/details/26364901 1.JS操作符 ① 除法 ...
- day056-58 django多表增加和查询基于对象和基于双下划线的多表查询聚合 分组查询 自定义标签过滤器 外部调用django环境 事务和锁
一.多表的创建 from django.db import models # Create your models here. class Author(models.Model): id = mod ...
- ASP.NET Core 2.0系列学习笔记-NLog日志配置文件
一.新建ASP.NET Core 2.0 MVC项目,使用NuGet在浏览中搜索:NLog.Web.AspNetCore,如下图所示: 二.在项目的根目录下新建一个xml类型的nlog.config文 ...
- Linux之正则表达式1
正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串”用来表达对字符串的一种过滤逻辑.适当使用正则表达式可以提高工作效 ...
- 【Python】断言功能Assertion
转自 https://www.cnblogs.com/cicaday/p/python-assert.html Python Assert 为何不尽如人意 Python中的断言用起来非常简单,你可以在 ...
- 二进制 转换成十进制 BCD码(加3移位法)
"原来的二进制数十几位,则左移时就要左移几位" "二进制数调整BCD码的方法是将二进制码左移8次,每次移位后都检查低四位LSD+3是否大于7,如是则加3,否则不加,高4位 ...
- springMVC框架返回JSON到前端日期格式化
在Controller类中,需要返回JSON的方法上加上注释@ResponseBody,这是必须的. 然后spring-servlet.xml配置如下: <?xml version=" ...
- 干掉hao123劫持浏览器主页
原因可能是安装某个软件流氓捆绑了IE主页导致的,建议这样尝试: 一.如果安装有三方安全防护类软件,排查流氓软件,建议运行系统自带的Windows Defender或者MSE程序扫描系统. 二.如果有检 ...