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 ...
随机推荐
- maven安装操作
首先检查我们的系统是否有安装JDK,检验方法:1.首先在我们的“文件资源管理器”地址栏输入cmd.在“文件资源管理器”地址栏输入cmd命令后,按下键盘上的“Enter”键,进入黑科技模式.在我们的“D ...
- 依据Axis2官网的高速入门英文文档总结
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/ksdb0468473/article/details/29918027 首先在Eclipse中创建一 ...
- laravel路由别名
在定义路由时使用数组键 as 指定路由名称: Route::get('user/profile', ['as' => 'profile', function () { // }]); 另外,还可 ...
- 函数和对象 及 prototype和__proto__
对象有 __proto__ 函数有 prototype 对象的__proto__指向构造自己的函数的prototype 但有一例外 var Obj = {v:99}var pObj = Object ...
- 验证代理ip是否可用
改编自:http://www.jianshu.com/p/588241a313e7 # _*_ coding:utf-8 _*_ import urllib2 import re class Test ...
- DSP2812 启动详解
百度文库转载 1. 从0X3F FFC0处复位→执行0X3F FC00地址处的初始化引导函数(Initboot) →根据GPIO选择引导模式→确定用户程序入口地址→从入口处开始执行用户程序. 输入外部 ...
- 如何从 VSS 迁移到Team Foundation Server
TFS 2012自带了vss upgrade wizard工具, 在Team Foundation Server管理控制台左侧的最后一个菜单其他工具和组件中,选择Visual SourceSafe升级 ...
- python 使用ElementTree解析xml
以country.xml为例,内容如下: <?xml version="1.0"?> <data> <country name="Liech ...
- 如何让Excel单元格中的名字分散对齐
1 操作方式 开始->对齐方式->对齐->水平对齐->分散对齐(缩进) 2 优势 不会破坏数据的有效性
- 知识点:Mysql 基本用法之函数
函数 MySQL中提供了许多内置函数 例如: sql 内置函数: 一.数学函数 ROUND(x,y) 返回参数x的四舍五入的有y位小数的值 RAND() 返回0到1内的随机值,可以通过提供一个参数(种 ...