Codeforces 1099 - A/B/C/D/E/F - (Done)
链接:https://codeforces.com/contest/1099
A - Snowball - [模拟水题]
题意:有一个雪球从山顶滚落,山坡上有两块石头,每秒钟会一次发生三件事:1、雪球增重,数值为当前高度;2、如果当前高度有一块石头,则会撞到石头,损失跟石头同样重的重量;3、往下移动一米。此外,若雪球的重量如果变为负数,则自动变成零。雪球会在高度为零处停止滚动,问停止滚动时雪球重量。
题解:模拟水题。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int w,h;
int u[],d[];
int main()
{
cin>>w>>h;
cin>>u[]>>d[]>>u[]>>d[];
while(h)
{
w+=h;
for(int i=;i<=;i++) if(h==d[i]) w-=u[i], w=max(w,);
h--;
}
cout<<w<<endl;
}
B - Squares and Segments - [简单数学题]
题意:在一个无限大的网格上画正方形,只能画单位 $1$ 长度的线段,且端点只能在整数格点上。你如果想画 $(x,y)$ 到 $(x,y+1)$ 这样一条线段,如果存在 $(x',y)$ 到 $(x',y+1)$ 的另外一条线段,则可以直接画,否则就需要用尺子。对于 $(x,y)$ 到 $(x+1,y)$ 这样的线段也是类似的。求最少用几次尺子能画出 $n$ 个正方形。
题解:显然,若 $n=k^2$,则 $ans=2 \cdot k$。否则的话,找到满足 $(k-1)^2 < n < k^2$ 的 $k$,而 $ans$ 为 $2 \cdot k$ 或者 $2 \cdot k - 1$。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int eps=1e-;
int n;
int main()
{
while(cin>>n)
{
int k=ceil(sqrt(n)-eps)+eps;
if(k*k==n) cout<<*k<<endl;
else
{
int t=n-(k-)*(k-);
cout<<((t>=k)?(*k):(*k-))<<endl;
}
}
}
C - Postcard - [简单的字符串构造题]
题意:给出一个小写字母组成的字符串,另外还包含“?”、“*”两个字符,“?”代表其前面的那个字母可以去掉或者留下,“*”代表其前面的那个字母可以重复零到任意多次。要求你给出一个长度为 $k$ 的操作后字符串。
题解:首先“Impossible”的原因有两种,一种是长度过长,另一种是长度过短,先把这两种判掉。
其次看看有没有“*”,如果没有,把一部分“?”前的字母留下来达到长度 $k$ 即可;如果有,那么别的全部扔掉,只用其中一个“*”重复字母,知道长度为 $k$。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int k;
string s;
int main()
{
cin>>s>>k; int c1=, c2=;
for(int i=;i<s.size();i++)
{
if(s[i]=='?') c1++;
if(s[i]=='*') c2++;
}
if(s.size()-*(c1+c2)>k) //长度过长
{
printf("Impossible\n");
return ;
}
if(c2== && s.size()-c1<k) //长度过短
{
printf("Impossible\n");
return ;
} int need=k-(s.size()-*(c1+c2)); //cout<<need<<endl;
if(c2>)
{
for(int i=;i<s.size();i++)
{
if(i+<s.size() && s[i+]=='?') {i++; continue;}
if(i+<s.size() && s[i+]=='*')
{
for(int t=;t<=need;t++) printf("%c",s[i]);
need=;
i++; continue;
}
printf("%c",s[i]);
}
printf("\n");
}
else
{
for(int i=;i<s.size();i++)
{
if(i+<s.size() && s[i+]=='?')
{
if(need){printf("%c",s[i]); need--; i++; continue;}
else {i++; continue;}
}
printf("%c",s[i]);
}
printf("\n");
}
}
D - Sum in the tree - [DFS]
题意:给出一棵有根树,根节点编号为 $1$,每个节点存在一个权值 $a[x]$,同时还有一个 $s[x]$ 为从根节点到节点 $x$ 这条路径上的所有节点的 $a[x]$ 之和。此时,擦除了所有深度为偶数的节点的 $s[x]$(根节点深度为 $1$)。然后要求反推出所有节点的 $a[x]$,使得所有节点的 $a[x]$ 之和最小。
题解:很容易就能想到,对于一个 $s[x] = -1$ 节点,它的 $a[x]$ 的取值是受制于它的所有直系子节点的。而且,它的儿子节点们的 $s[y]$ 都是确保已知的,因此只存在两种情况:有儿子节点,$s[x]$ 取值就是 $\min_{所有的edge(x,y)}(s[y])$,进而 $a[x] = s[x] - s[par(x)]$;如果没有儿子节点,那么显然取 $a[x] = 0$ 是最好的。然后根据这种思想,用DFS遍历一下树,算出每个节点的 $a[x]$ 就行了。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=1e5+;
int n,a[maxn],s[maxn];
vector<int> e[maxn];
bool ok;
void dfs(int now,int par,int d)
{
if(!ok) return;
if(d%==)
{
if(e[now].empty()) s[now]=s[par], a[now]=;
else
{
int mn=INF;
for(auto nxt:e[now]) mn=min(mn,s[nxt]);
if(mn<s[par]) {ok=; return;}
else s[now]=mn, a[now]=s[now]-s[par];
}
}
else a[now]=s[now]-s[par];
for(auto nxt:e[now]) dfs(nxt,now,d+);
}
int main()
{
cin>>n;
for(int v=,u;v<=n;v++) scanf("%d",&u), e[u].push_back(v);
for(int i=;i<=n;i++) scanf("%d",&s[i]); ok=, s[]=;
dfs(,,); if(!ok) cout<<-<<endl;
else
{
ll ans=;
for(int i=;i<=n;i++) ans+=a[i];
cout<<ans<<endl;
}
}
E - Nice table
F - Cookies - [DFS+博弈+线段树]
Codeforces 1099 - A/B/C/D/E/F - (Done)的更多相关文章
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror] F. Bulbo DP
F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Des ...
- Codeforces 1154 - A/B/C/D/E/F/G - (Undone)
链接:https://codeforces.com/contest/1154 A - Restoring Three Numbers - [水] #include<bits/stdc++.h&g ...
- Educational Codeforces Round 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理
https://codeforces.com/contest/1101/problem/F 题意 有n个城市,m辆卡车,每辆卡车有起点\(s_i\),终点\(f_i\),每公里油耗\(c_i\),可加 ...
- Codeforces 670 - A/B/C/D/E/F - (Done)
链接:https://codeforces.com/contest/670 A - Holidays - [水] AC代码: #include<bits/stdc++.h> using n ...
- Codeforces 1132 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1132 A - Regular Bracket Sequence - [水] 题解:首先 "()" 这个的数量多 ...
- Codeforces 1114 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1114 A - Got Any Grapes? 题意:甲乙丙三个人吃葡萄,总共有三种葡萄:绿葡萄.紫葡萄和黑葡萄,甲乙丙三个人至少要 ...
- Codeforces 1043 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1043 A - Elections - [水水水水题] 题意: 我和另一个人竞争选举,共有 $n$ 个人投票,每个人手上有 $k$ ...
随机推荐
- JS获取当前日期、比较日期大小
//获取当前时间,格式YYYY-MM-DD function getNowFormatDate() { var date = new Date(); var seperator1 = "-& ...
- Ubuntu18.04下可以完美运行Quake3 Arena
安装 其实很早就知道Linux下面可以跑Quake3, 但是一直没有付诸行动, 在硬盘上躺了很多年的Quake III Arena, 和Brood一起从来不舍得删, 昨天终于想起来试试. 安装很简单, ...
- Typora的使用
Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式,其目标是实现易读易写.我刚刚接触一款简单高效的Markdown编辑器–Typora, ...
- Asp.Net WebApi上传图片
webapi using System; using System.Collections; using System.Collections.Generic; using System.Diagno ...
- Replication基础(六) 复制中的三个线程(IO/SQL/Dump)
Reference: https://blog.csdn.net/sun_ashe/article/details/82181811?utm_source=blogxgwz1 简介在MySQL复制技 ...
- IOS-企业开发人员账号&邓白氏码申请记录
Apple开发人员账号分三种,个人.公司,还有企业.个人和公司都称为标准账号. 另一种是教育机构的账号. 账号介绍 个人和公司的就不说了.如今仅仅说企业账号 首先是申请企业账号的地址: https:/ ...
- 【iCore4 双核心板_ARM】例程三十八:DSP MATH库测试
实验现象: 核心代码: int main(void) { /* USER CODE BEGIN 1 */ int i,j; int res; ]; ; /* USER CODE END 1 */ /* ...
- java 中 ResourceBundle 使用 国际化使用
java 中 ResourceBundle 使用 可以根据以下类进行获取国际化文件: package org.mybatis.generator.internal.util.messages; imp ...
- myeclipse中的项目 如何在项目视窗中显示setting,classpath等配置文件
导入了别人的项目,各种jar包都放好后,path也都build好了,项目也能正常启动,但是就是项目名有红叉,这是为什么呢? 网上有人说Java build path中的jar包missing了,这是一 ...
- windows下自动删除过期文件的脚本
windows下自动删除过期文件的脚本 前言: 比如日志文件每天都产生,时间长了就会有很大的一堆垃圾.整理一下 定时删除文件的方法. 正文: Windows: 定时删除tomcat日志和缓存.可以保留 ...