A: Stages

题意:

给你n个字符, 现在需要从中选取m个字符,每个字符的花费为在字母表的第几位,并且如果选了某个字符, 那么下一个选择的字符必须要在字母表的2位之后, 假如选了e 那么 不能选 a-f 可以选择 g-z, 现在求能满足条件的最小花费。

题解:

直接模拟。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int cnt[N];
char s[N];
int main(){
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", s+);
for(int i = ; i <= n; i++){
cnt[s[i]-'a']++;
}
int ans = ;
for(int i = ; i < && m; i++){
if(cnt[i]){
m--;
ans += i+;
i++;
}
}
if(m) puts("-1");
else printf("%d\n", ans);
return ;
}

B:Planning The Expedition

题意:

有n个人要去火星, 现在有m份食物, 每个人在火星生存的时候一天消耗一份食物, 并且每天的消耗的食物必须是同一种类的, 不同的人可以选择不同种类的食物。 现在求这n个人最多能在火星上待几天。

题解:

暴力模拟。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int cnt[N];
int main(){
int n, m, u;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++){
scanf("%d", &u);
cnt[u]++;
}
for(int i = m; i >= ; i--){
int tot = ;
for(int j = ; j <= ; j++)
tot += cnt[j]/i;
if(tot >= n) {
printf("%d\n", i);
return ;
}
}
puts("");
return ;
}

C:Fly

题意:

现在有1-n, n个星球, 现在某个人要按 1 -> 2 -> 3 -> 4 -> ... -> n -> 1的方式走完旅行, 他先再1号星球上起飞, 然后在2号星球降落, 再从2号星球起飞  ...  在n号星球降落,n号星球起飞, 1号星球降落。就完成了旅行。

每个星球有一个起飞系数 ai 有一个降落系数 bi, 每一 ton 燃料 可以带动 ai / bi 的重量的东西 起飞/降落, 现在他乘着 m ton的火箭, 然后问带最小多少 ton 的燃料可以完成旅行, 如果完成不了输出-1;。

题解:

听说好像是可以倒着模拟, 我觉得也是可以的。

我本人写的是2分, 2分燃料, 然后每次都check一下, 判断是否可以, 如果可以就减少燃料上限, 如果不行就增加燃料下限, 最后跑完2分之后在check一下燃料值, 如果可以就输出答案, 不行就输出-1。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
double eps = 1e-;
int a[N], b[N];
int n, m;
bool check(double mm){
double weight = mm + m;
double need;
for(int i = ; i <= n; i++){
need = (mm+m)/a[i];
if(need > mm) return false;
mm -= need;
need = (mm+m)/b[i];
if(need > mm) return false;
mm -= need;
}
return true;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]);
scanf("%d", &b[n]);
for(int i = ; i < n; i++)
scanf("%d", &b[i]);
double l = , r = 2e9, mm ;
for(int i = ; i <= ; i++){
mm = (l+r) / ;
if(check(mm)) r = mm;
else l = mm;
}
if(check(r)) printf("%.8f", r);
else printf("-1");
return ;
}

D:Rocket

交互题

题意:

某个人在地球去火星的路上,这段路程为 m , 现在他想知道有他现在离火星的距离是多少,他可以向火箭猜测现在他与火星的距离是多少,假设实际距离为 x ,现在他猜了y ,如果 y > x 则 火箭会返回 -1,如果 x == y 火箭会返0 ,  y < x 火箭会返回1 。但是火箭回答程序有一些损坏,有时候会回答出相反的答案, 即正确答案为1 他会返回 -1,0 返回0 ,-1返回1。 但是火箭回答正确与否是有周期的, 周期为n。 现在你最多询问60次, 要求输出正确的 x 值是多少。

题解:因为n最多30, 我们可以在第一段周期都输入0, 如果返回0, 那么说名实际距离就是0,否则的话, 那么实际距离一定 > 1, 那么我们就可以知道回答问题正确和相反是按照哪个周期了。接下来我们2分答案就好了。

注意的就是找到答案的时候要及时退出,并且输出的时候要换行。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int a[N];
int main(){
int m, n;
scanf("%d%d", &m, &n);
for(int i = ; i <= n; i++){
printf("1\n");
fflush(stdout);
scanf("%d", &a[i]);
if(a[i] == ){
printf("%d\n", );
exit();
}
}
for(int i = ; i <= n; i++)
a[i] *= -;
int cnt = ;
int l = , r = m+, mid;
int t;
while(){
mid = l+r >> ;
printf("%d\n", mid);
fflush(stdout);
scanf("%d", &t);
if(t == ) {
printf("%d\n", mid);
exit();
}
t *= a[cnt];
cnt++;
if(cnt > n) cnt = ;
if(t < ) l = mid;
else r = mid;
}
return ;
}

E:Border

题意:

某个人去火星旅游,但是去火星旅游需要缴入门费,火星上的货币是以k进制进行的,并且火星上的人觉得 d 数字是神圣的,如果入门费的最后一位的数字是 d (基于k进制)那么火星人就会很开心,不幸的是我们不知道火星人觉得哪个数字是神圣的, 现在有 n 种面值为 ai 的货币(基于10进制), 每种货币都有有无穷个, 现在问在任意组合下, 最后能组合出多少个不同的最后一位的数字, 并且按大小输出所有的可以组成的数。

题解:

ax + by = z

如果给定a,b,z之后该方程有解, 那么 z % gcd(a,b) == 0, 所以我们求出所有面值关于k的 gcd 以及 所有面值之间的 gcd, 那么所有这些gcd倍数的值都可以被表示出来。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int a[N];
int vis[N];
int cnt = ;
int main(){
int n, k;
scanf("%d%d", &n, &k);
int last = k;
for(int i = ; i <= n; i++){
scanf("%d", &a[i]);
a[i] %= k;
if(a[i]){
last = __gcd(a[i], last);
a[i] = __gcd(a[i], k);
vis[a[i]] = ;
}
else vis[] = ;
}
vis[last] = ;
for(int i = ; i < k; i++){
if(vis[i]){
cnt++;
for(int j = i*; j <= k; j+=i)
vis[j] = ;
}
}
vis[] |= vis[k];
if(vis[]) cnt++;
printf("%d\n", cnt);
for(int i = ; i < k; i++){
if(vis[i]) printf("%d ", i);
}
return ;
}

F:Mars rover

题意:一道模拟门电路的题。题目要求输出每个信号输入的位置取反之后最后 1 号位置的值是多少。

题解:先模拟出最开始的型号,并且处理出如果上一个位置的状态发生改变该位置的信号会不会发生改变,如果会发生改变,就标记一下上一个位置, 最后先dfs完一遍之后,就可以处理出每个位置发生改变之后会不会导致下一个位置的信息发生改变。 我们再从1号节点遍历一遍, 如果某个位置没有被标记过, 那么就清除他所有子节点的标记。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e6 + ;
int n;
int op[N];/// 1 -> & 2 -> ^ 3 -> not 4 -> in
int ok[N];
int val[N];
int ans[];
char s[];
vector<int> son[N];
void dfs(int u){
if(op[u] == ) return ;
for(int i = ; i < son[u].size(); i++) dfs(son[u][i]);
int x = son[u][];
if(op[u] == ){
val[u] = ^ val[x];
ok[x] = ;
}
int y = son[u][];
if(op[u] == ){
val[u] = val[x] & val[y];
if(val[y] == ) ok[x] = ;
if(val[x] == ) ok[y] = ;
}
else if(op[u] == ){
val[u] = val[x] ^ val[y];
ok[x] = ok[y] = ;
}
else if(op[u] == ){
val[u] = val[x] | val[y];
if(val[x] == && val[y] == ) ok[x] = ;
if(val[x] == && val[y] == ) ok[y] = ;
if(val[x] == && val[y] == ) ok[x] = ok[y] = ;
}
}
void dfs2(int u, int flag){
ok[u] &= flag;
for(int i = ; i < son[u].size(); i++)
dfs2(son[u][i], ok[u]);
}
int main(){
scanf("%d", &n);
int u, v;
for(int i = ; i <= n; i++){
scanf("%s", s+);
if(s[] == 'I') op[i] = , scanf("%d", &val[i]);
else if(s[] == 'N'){
scanf("%d", &u);
son[i].pb(u);
op[i] = ;
}
else {
scanf("%d%d", &u, &v);
son[i].pb(u); son[i].pb(v);
if(s[] == 'A') op[i] = ;
if(s[] == 'X') op[i] = ;
if(s[] == 'O') op[i] = ;
}
}
dfs();
ok[] = ;
dfs2(,);
ans[] = val[]; ans[] = val[] ^ ;
for(int i = ; i <= n; i++)
if(op[i] == ) printf("%d", ans[ok[i]]);
return ;
}

CodeForces Round #499 Div2的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. Codeforces Round #499 (Div. 2)

    Codeforces Round #499 (Div. 2) https://codeforces.com/contest/1011 A #include <bits/stdc++.h> ...

  3. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  4. Codeforces Round #499 (Div. 1)部分题解(B,C,D)

    Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...

  5. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  6. Codeforces Round #499 (Div. 1)

    Codeforces Round #499 (Div. 1) https://codeforces.com/contest/1010 为啥我\(\rm Div.1\)能\(A4\)题还是\(\rm s ...

  7. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  8. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  9. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

随机推荐

  1. python多线程详解

    目录 python多线程详解 一.线程介绍 什么是线程 为什么要使用多线程 二.线程实现 threading模块 自定义线程 守护线程 主线程等待子线程结束 多线程共享全局变量 互斥锁 递归锁 信号量 ...

  2. 新IT运维时代 | Docker运维之最佳实践-上篇

    容器技术的发展可以分为两个阶段,第一个阶段聚焦在IaaS层,仅仅把容器当做更轻量级虚拟机来使用,解决了应用运行时进程级资源隔离的问题:随着Docker的出现,容器虚拟化才有了统一的平台,由此容器技术发 ...

  3. Cannot attach the file “MvcMovie.mdf” as database “aspnet-MvcMovie”

    今天在微软开发人员官网上学习asp.net mvc5入门的时候,遇到一个棘手的问题,我是按照教程一步一步操作的,但期间遇到一个自己觉得莫名其妙的问题,教程中也没有提到这个, 在添加新字段这一章节,跟着 ...

  4. FTP工具-FileZilla安装使用教程

    1.首先,百度搜索“FileZilla”,进入官网,下载地址:https://www.filezilla.cn/download/client  ,根据自己电脑配置去下载 2.下载本地,双击运行安装程 ...

  5. 解决VS2008,重新生成解决方案,很慢

    正所谓:“工欲善其事,必先利其器“.我也算是深受其害了,特把经验分享出来为大伙分忧! 在刚来公司的时候,使用的公司提供的VS2008作为开发工具,有一个非常让人不爽的问题,就是在重新编译代码(重新生成 ...

  6. 【POJ - 2229】Sumsets(完全背包)

    Sumsets 直接翻译了 Descriptions Farmer John 让奶牛们找一些数加起来等于一个给出的数N.但是奶牛们只会用2的整数幂.下面是凑出7的方式 1) 1+1+1+1+1+1+1 ...

  7. Pipeline 模型

    解决的问题 解决并发效率问题,将任务拆分成流水线,然后多线程并发执行,比之单线程执行快. 案例 CPU 流水线 Tomcat 容器 Structs

  8. 10分钟安装Elasticsearch

    关注公众号 itweknow,回复"ES"获取<Elasticsearch权威指南 中文版>. 最近在尝试着搭建一个ELK(一个开源的实时日志分析平台),而本文所讲的E ...

  9. centos部署oracle rac单实例11.2.0.3数据库(使用asm磁盘)

    部署oracle rac单实例数据库,需要安装grid和datavase两部分,所以首先创建两个用户oracle和grid,因为不能使用root用户进行安装,在安装之前首先需要修改一些系统参数和安装一 ...

  10. 每天用SpringBoot,还不懂RESTful API返回统一数据格式是怎么实现的?

    上一篇文章RESTful API 返回统一JSON数据格式 说明了 RESTful API 统一返回数据格式问题,这是请求一切正常的情形,这篇文章将说明如何统一处理异常,以及其背后的实现原理,老套路, ...