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. Maven项目的打包发布到Nexus私服和服务器

    1.编写pom文件如下: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins< ...

  2. 无法正常卸载pr

    控制面板找不到pr和ps,根本无法卸载,我试过官方工具没用,也试过ccleaner,也检测不到?

  3. 封装 Gson 解析Json到对象是否失败

    在使用Google的 Gson 类库解析 Json 数据时,难免会出现解析失败的情况. 在这种情况下,使用 if(obj == null) 是不可行的,fromJson 方法会自动生成对象的实例,所以 ...

  4. 洛谷P1510 题解

    前言: 其实这道题挺水的,但我居然把ta想成了 贪心 啪啪打脸 好了,废话不多说. 思路: step 1:先翻译以下题意,其实就是求出最多消耗多少体力能把东海填满,如果不能填满,就输出"Im ...

  5. canvas 使用图片跨域问题

    项目中需要生成海报,使用了前端生成图片的插件,将背景图,详情图,以及部分的文字说明放在一块并且生成一张新的图片,大体看了一下源码是通过canvas来实现的,在本地的时候完全没有问题,提交到服务器之后就 ...

  6. 【数据结构】线段树(Segment Tree)

    假设我们现在拿到了一个非常大的数组,对于这个数组里面的数字要反复不断地做两个操作. 1.(query)随机在这个数组中选一个区间,求出这个区间所有数的和. 2.(update)不断地随机修改这个数组中 ...

  7. (三十三)c#Winform自定义控件-日期控件

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  8. c# oracle 数据库连接以及参数化查询

    private string OracleSearchDemo(string cadqueueId) { string address = null; using (OracleConnection ...

  9. Yii GridView Ajax 刷新

    Yii GridView  Ajax 刷新,当页面点击一个按钮时,刷新数据. 1.控制器 <?php class privController extends Controller{ publi ...

  10. netty源码解解析(4.0)-18 ChannelHandler: codec--编解码框架

    编解码框架和一些常用的实现位于io.netty.handler.codec包中. 编解码框架包含两部分:Byte流和特定类型数据之间的编解码,也叫序列化和反序列化.不类型数据之间的转换. 下图是编解码 ...