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. 【转载】C/C++中long long与__int64的区别

    在C99标准(详情请猛击:C语言的发展及其版本)中,增加了对64位长整型数据的支持,它的类型就是 long long,占用8个字节. 由于C99标准发布较晚,一些较老的C/C++编译器不支持,新编译器 ...

  2. WinForm开发中通用附件管理控件设计开发参考

    1.引言 在WinForm开发中,文件附件的管理几乎在任何一个应用上都会存在,是一个非常通用集中的公共模块.我们日常记录会伴随着有图片.文档等附件形式来展现,如果为每个业务对象都做一个附件管理,或者每 ...

  3. SpringBoot:如何优雅地处理全局异常?

    之前用springboot的时候,只知道捕获异常使用try{}catch,一个接口一个try{}catch,这也是大多数开发人员异常处理的常用方式,虽然屡试不爽,但会造成一个问题,就是一个Contro ...

  4. Meta 用法汇总

    本文引自: http://blog.csdn.net/MR_LP/article/details/53607087 什么是 meta ? meta 是html语言head区的一个辅助性标签.也许你认为 ...

  5. 汇总VSCode中比较好用的插件

    使用vscode编辑器两年的时间,总结出前端一些比较方便的插件 1. Auto Close Tag 自动添加HTML / XML关闭标签 2. Auto Complete Tag 自动完成标签 3 A ...

  6. 《机器学习技法》---soft-margin SVM

    1. soft-margin SVM的形式 其中ξn表示每个点允许的犯错程度(偏离margin有多远),但是犯错是有代价的,也就是目标函数里面要最小化的.c控制对犯错的容忍程度. 2. 推导soft ...

  7. 敏捷社区--敏捷与OKR

    携程敏捷总动员是由携程技术管理中心(PMO)发起的敏捷项目管理线下主题沙龙活动(每2月一次),旨在和研发管理同行分享互联网行业第一线的优秀敏捷实践.     5月10日携程敏捷总动员-OKR专场活动, ...

  8. 聊聊我在这家公司设计的SSO

    最近小明遇到一个需求:需要将几个独立的系统(子系统)汇总到一个集中的系统(父系统)当中,当用户在父系统登录过后,再点击这几个子系统,就可以免登录跳转到任意一个系统.当时一听,duang~duang~就 ...

  9. 【在 Nervos CKB 上做开发】Nervos CKB脚本编程简介[2]:脚本基础

    CKB脚本编程简介[2]:脚本基础 原文作者:Xuejie 原文链接:Introduction to CKB Script Programming 2: Script 本文译者:Shooter,Jas ...

  10. com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect

    com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: con ...