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$ ...
随机推荐
- oralce 11.2.0.4手动创建EM
安装完oracle,启动dbconsole,失败 [oracle@elearning admin]$ emctl start dbconsole OC4J Configuration issue. / ...
- 转【微信小程序 四】二维码生成/扫描二维码
原文:https://blog.csdn.net/xbw12138/article/details/75213274 前端 二维码生成 二维码要求:每分钟刷新一次,模拟了个鸡肋,添加了个按分钟显示的时 ...
- [转]调试利器-SSH隧道
在开发微信公众号或小程序的时候,由于微信平台规则的限制,部分接口需要通过线上域名才能正常访问.但我们一般都会在本地开发,因为这能快速的看到源码修改后的运行结果.但当涉及到需要调用微信接口时,由于不和你 ...
- bootstrap 前端模板
https://colorlib.com/wp/free-bootstrap-admin-dashboard-templates/
- CentOS 7 使用 ACL 设置文件权限
Linux 系统标准的 ugo/rwx 集合并不允许为不同的用户配置不同的权限,所以 ACL 便被引入了进来,为的是为文件和目录定义更加详细的访问权限,而不仅仅是这些特别指定的特定权限. ACL 可 ...
- 无法加载协定为“ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。
原因是在web.config 文件中多次引用了“添加外部引用” <system.serviceModel> <bindings> <basicHttpBinding> ...
- 【Java】类加载过程
JVM把class文件加载到内存,并对数据进行校验.解析和初始化,最终形成JVM可以直接使用的Java类型的过程. 类加载的过程主要分为三个部分: 加载 链接 初始化 而链接又可以细分为三个小部分: ...
- python 字符编码判断 chardet评测
之前一直想找到一个模块,针对字符判断是什么字符集编码的库 网上有chardet的blog,发现自己的环境有这个库,于是就做了测试 >>> import chardet >> ...
- FlexCel 插入公式和插入新行
//http://www.tmssoftware.biz/flexcel/doc/vcl/api/FlexCel.Core/TExcelFile/InsertAndCopyRange.html#tex ...
- 使用Apache下poi创建和读取excel文件
一:使用apache下poi创建excel文档 @Test /* * 使用Apache poi创建excel文件 */ public void testCreateExcel() { // 1:创建一 ...