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 ...
随机推荐
- 前后端如何保持长连接?---websocket
1. pc端的应用,一般会采用前端定时请求后台; 2. app定时去访问后台的话,对用户来说并不友好,会消耗大量的流量,移动端最好的方式就是后台主动向app推送信息; 3. H5提供了一种比较好的方式 ...
- django无法同步mysql数据库 Error:1064
[问题] 具体问题:新建django工程,使用django的manage.py的 migrate命令进行更改. 在初始化数据库表时,失败,错误信息为 django.db.migrations.exce ...
- 在xcode 上调试c程序
打开xcode 选择 Create a new Xcode project 选择Command Line Tool 给你的项目起个名,选择c语言 点击next 选择存储位置,就会制动生成一个项目,在项 ...
- docker的ubuntu镜像无ifconfig和ping netstat命令
docker的ubuntu镜像无ifconfig和ping命令 或者 ubuntu系统中无ifconfig 和 ping 解决方案: 执行以下鸣冷: apt-get update apt-get in ...
- python configparser使用
.ini文件由若干section(部分)组成, 而每一个section又由若干键值对组成. 以 example.ini为例: [DEFAULT] ServerAliveInterval = 45 Co ...
- spring4.0之二:@Configuration的使用
从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被AnnotationConfigApplic ...
- [转][C#]程序的动态编译
转自:https://blog.csdn.net/clb929/article/details/51385399 附 文件下载
- 安装zookeeper遇到的问题
最近在安装zookeeper的时候遇到了一个问题:调用./zkServer.sh start之后,使用命令telnet localhost 2181,显示访问被拒绝.然后使用netstat查看监听21 ...
- WHERE 子句操作符
操作符(operator) 用来联结或改变WHERE子句中得子句的关键字,也称为逻辑操作符(logical operator): 操作符 说 明 = 等于 <> 不等于 != 不等于 & ...
- You Only Look Once: Unified, Real-Time Object Detection
论文下载:http://arxiv.org/abs/1506.02640 代码下载:https://github.com/pjreddie/darknet Abstract 作者提出一种新的目标检测 ...