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 ;
}

最新文章

  1. HSDB - HotSpot debugger
  2. python在线文档
  3. Import SHA2 SSL cert to Windows IIS7
  4. MyEclipse — Maven+Spring+Struts+Hibernate 整合 [学习笔记-5]
  5. 《学习OpenCV》练习题第四章第七题abc
  6. 使用Discuz!自带参数防御CC攻击以及原理,修改Discuz X 开启防CC攻击后,不影响搜索引擎收录的方法
  7. 经典系统windows xp sp3官方原版下载(附XP序列号)
  8. 一个sql的优化
  9. PostgreSQL 的 distinct on 的理解
  10. python并发编程之多进程(理论)
  11. 2018.4.25-ml笔记(梯度下降)
  12. 学习windows编程 day3 之滚动条完善
  13. 虚拟货币ICO是什么意思 看完秒懂
  14. WPF实战案例-数据代理
  15. 通过淘宝接口免费获取IP地址信息
  16. group by 小结
  17. paxos ---学习笔记
  18. js作用域链以及全局变量和局部变量
  19. 关于FusionCharts需要第一次点击切换才出现问题
  20. 指向“**js/shop.js”的 &lt;script&gt; 加载失败

热门文章

  1. Chrome浏览器F12开发者工具简单使用
  2. eclipse的下载安装配置
  3. AppBoxFuture: 123挨个站-数据按序存储
  4. Unity经典游戏编程之:球球大作战
  5. GooglePlay新版排行榜接入
  6. android ——后台下载
  7. 动态SQL查询
  8. 如何获取app中的toast
  9. 从MYSQL的ibtmp1文件太大说起
  10. javaScript基础-0 javascript概述