CodeForces Round #499 Div2
题意:
给你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 ;
}
题意:
有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 ;
}
题意:
现在有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 ;
}
交互题
题意:
某个人在地球去火星的路上,这段路程为 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 ;
}
题意:
某个人去火星旅游,但是去火星旅游需要缴入门费,火星上的货币是以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 ;
}
题意:一道模拟门电路的题。题目要求输出每个信号输入的位置取反之后最后 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的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Codeforces Round #499 (Div. 2)
Codeforces Round #499 (Div. 2) https://codeforces.com/contest/1011 A #include <bits/stdc++.h> ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- 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 ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
随机推荐
- Linux常用的命令及使用方法
1.请用命令查出ifconfig命令程序的绝对路径 [root@localhost ~]# which ifconfig(ifconfig是linux中用于显示或配置网络设备(网络接口卡)的命令) / ...
- 自定义SWT控件二之自定义多选下拉框
2.自定义下拉多选框 package com.view.control.select; import java.util.ArrayList; import java.util.HashMap; im ...
- thinkphp3.2使用七牛云上传文件
最近项目中用到了七牛云服务,来分享一下thinkphp使用七牛云来进行文件上传 1.首先在七牛云创建一个空间,例如空间名为test.获取secrectKey,accessKey 2.在thinkphp ...
- Linux基础进程管理优先级
一.进程优先级 Linux进程调度及多任务 每个cpu(或者cpu核心)在一个时间点上只能处理一个进程,通过时间片技术,Linux实际能够运行的进程(和线程数)可以超出实际可用的cpu及核心数量.Li ...
- Java VisualVM监控远程JVM
我们经常需要对我们的开发的软件做各种测试, 软件对系统资源的使用情况更是不可少, 目前有多个监控工具, 相比JProfiler对系统资源尤其是内存的消耗是非常庞大,JDK1.6开始自带的VisualV ...
- javascript 异步请求封装成同步请求
此方法是异步请求封装成同步请求,加上token验证,环境试用微信小程序,可以修改文件中的ajax,进行封装自己的,比如用axios等 成功码采用标准的 200 到 300 和304 ,需要可以自行修改 ...
- Unity场景和代码合并以及UnityYAMLMerge的使用
1.首先是.gitignore的配置. # Folder config file Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ ...
- 在一个含有1-n的序列中,每次找到第Ki小的数,并把它删除(线段树)
提交链接 Data structure is one of the basic skills for Computer Science students, which is a particular ...
- ccf 201809-4 再卖菜
这题一开始不知道剪枝这种操作,只会傻傻地dfs. 然后dfs递归写80分超时,非递归写70分超时(纳尼?我一直以为非递归算法在时间上会更优秀一些,为什么会这样?!!) 剪一下枝就都能过了 #inclu ...
- 测试自动化:java+selenium3 UI自动化(2) - 启动Firefox
1. selenium和浏览器 基于selenium的这套自动化体系,其实现关键就在于对于各浏览器的顺畅操作. 事实上当selenium刚开始起家的时候,他使用的还是javascript注入的方式来驱 ...