题目链接

A. Vasya and Chocolate

题意

已知钱,价格,赠送规则求最多获得巧克力数

思路
常规算即可

代码

#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long LL; LL t,s,a,b,c; int main(){
cin >> t;
while(t--){
cin >> s >> a >> b >> c;
LL ans=s/c;
ans+=(ans/a)*b;
cout << ans << endl;
}
return 0;
}

B. Vasya and Isolated Vertices

题意

给出无向图点和边数问最多和最少孤立点的数量

思路

使孤立点尽可能少就让一条边尽可能消去两个点,否则让其尽可能消去一个点

代码

#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long LL; LL n,m,i; int main(){
scanf("%I64d%I64d",&n,&m);
while(i*(i-1)/2 < m)i++;
printf("%I64d %I64d\n",(m*2 < n) ? n-m*2 : 0,n-i);
return 0;
}

C. Make It Equal

题意

给出一些块柱,每次移动一层及以上所有块,在一次不移动超过k的前提下使所有柱高度一致的最少次数

思路

枚举当前移动的高度,使被移动的块尽可能接近k,需要预处理每层会影响的块数,枚举高度二分找位置,维护后缀即可完成预处理

代码

#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+5;
using namespace std; int n,k,a[maxn],maxH=-inf;
int b[maxn];
vector<int>vec; int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+1+n);
for(int i=2;i<=n;i++){
int det=a[i]-a[1];
maxH=max(maxH,det);
if(det)vec.push_back(det);
}
int siz=vec.size();
for(int i=maxH;i>=1;i--){
b[i]=lower_bound(vec.begin(),vec.end(),i)-vec.begin()+1;
b[i]=siz-b[i]+1;
b[i]+=b[i+1];
}
int now=0,cnt=0;
for(int i=maxH;i>=1;i--){
if(b[i]-now > k)now=b[i+1],cnt++;
}
if(now != b[1] && b[1]-now <= k)cnt++;
printf("%d\n",cnt);
return 0;
}
D. Three Pieces
题意
给定棋盘和三颗棋子,问遍历棋盘的最少步数即满足最少步数前提下替换棋子的最少次数
思路
从起点开始大力搜索,枚举所有可能的后继状态
代码
#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl;
const int maxn = 15;
const int maxm = 205;
const int inf = 0x3f3f3f3f;
using namespace std; int n,k;
int mp[maxn][maxn],vis[maxn][maxn],dp[maxn][maxn][3][maxm][maxm];
int sx,sy,ex,ey;
int dx1[8][2]={{-2,-1},{-2,1},{2,-1},{2,1},{-1,-2},{-1,2},{1,-2},{1,2}};
int dx2[4][2]={{-1,0},{1,0},{0,1},{0,-1}};
int dx3[4][2]={{-1,-1},{-1,1},{1,-1},{1,1}};
int ans=inf; struct node{
int r,c,who,time,pre;
node(int _r,int _c,int _who,int _time,int _pre){
r=_r,c=_c,who=_who,time=_time,pre=_pre;
}
}; void bfs(int sx, int sy) {
memset(dp, -1, sizeof dp);
dp[sx][sy][0][0][1] = dp[sx][sy][1][0][1] = dp[sx][sy][2][0][1] = 0;
queue<node>q;
q.push(node(sx, sy, 0, 0, 1));
q.push(node(sx, sy, 1, 0, 1));
q.push(node(sx, sy, 2, 0, 1));
while(!q.empty()) {
node nd = q.front();
q.pop();
int x = nd.r, y = nd.c, z = nd.who, t = nd.time, k = nd.pre;
for(int i = 0; i < 3; i++) {
if(i == z) continue;
if(dp[x][y][i][t + 1][k] != -1) continue;
dp[x][y][i][t + 1][k] = dp[x][y][z][t][k] + 1;
q.push(node(x, y, i, t + 1, k));
}
if(z == 0) {
for(int i = 0; i < 8; i++) {
int nx=x+dx1[i][0];
int ny=y+dx1[i][1];
int nk=k;
if(nx < 1 || nx > n || ny < 1 || ny > n) continue;
if(mp[nx][ny] == k + 1) nk++;
if(dp[nx][ny][z][t][nk] != -1) continue;
dp[nx][ny][z][t][nk] = dp[x][y][z][t][k] + 1;
q.push(node(nx, ny, z, t, nk));
}
}
if(z == 1) {
for(int i = 0; i < 4; i++) {
for(int j = 1;j <= 10;j++) {
int nx=x+j*dx2[i][0];
int ny=y+j*dx2[i][1];
int nk=k;
if(nx < 1 || nx > n || ny < 1 || ny > n) continue;
if(mp[nx][ny] == k + 1) nk++;
if(dp[nx][ny][z][t][nk] != -1) continue;
dp[nx][ny][z][t][nk] = dp[x][y][z][t][k] + 1;
q.push(node(nx, ny, z, t, nk));
}
}
}
if(z == 2) {
for(int i = 0; i < 4; i++) {
for(int j = 1;j <= 10;j++) {
int nx=x+j*dx3[i][0];
int ny=y+j*dx3[i][1];
int nk=k;
if(nx < 1 || nx > n || ny < 1 || ny > n) continue;
if(mp[nx][ny] == k + 1) nk++;
if(dp[nx][ny][z][t][nk] != -1) continue;
dp[nx][ny][z][t][nk] = dp[x][y][z][t][k] + 1;
q.push(node(nx, ny, z, t, nk));
}
}
}
}
}
int main(){///0 == knight,1 == bishop,2 == rook
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&mp[i][j]);
if(mp[i][j] == 1){sx=i;sy=j;}
if(mp[i][j] == n*n){ex=i;ey=j;}
}
}
bfs(sx,sy);
for(int i=0;i<maxm;i++){
for(int j=0;j<3;j++){
if(dp[ex][ey][j][i][n*n] != -1)ans=min(ans,dp[ex][ey][j][i][n*n]);
}
}
for(int i=0;i<maxm;i++){
for(int j=0;j<3;j++){
if(dp[ex][ey][j][i][n*n] == ans){printf("%d %d\n",ans,i);return 0;}
}
}
}

E. Side Transmutations

看这篇

F. Up and Down the Tree

看这篇

Educational Codeforces Round 52 (Rated for Div. 2)的更多相关文章

  1. Educational Codeforces Round 52 (Rated for Div. 2) E. Side Transmutations

    http://codeforces.com/contest/1065/problem/E 数学推导题 #include <bits/stdc++.h> using namespace st ...

  2. Educational Codeforces Round 52 (Rated for Div. 2) -C

    #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...

  3. Educational Codeforces Round 52 (Rated for Div. 2) F. Up and Down the Tree 树型DP

    题面 题意:给你一棵树,你起点在1,1也是根节点,你每次可以选择去你子树的某个叶子节点,也可以选择,从叶子节点返回距离不超过k的一个根, 也就是说,你从1开始,向下跳,选择一个叶子(就是没有子树的节点 ...

  4. Educational Codeforces Round 117 (Rated for Div. 2)

    Educational Codeforces Round 117 (Rated for Div. 2) A. Distance https://codeforces.com/contest/1612/ ...

  5. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  7. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  8. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  9. 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 ...

随机推荐

  1. HTML5 canvas clearRect() 方法

    浏览器支持 Internet Explorer 9.Firefox.Opera.Chrome 以及 Safari 支持 clearRect() 方法. 注释:Internet Explorer 8 或 ...

  2. PHP7--PHP的一次重大变革

    PHP7--PHP的一次重大变革 一.写在开头 PHP7是PHP编程语言全新的一个版本,主要在性能方面获得了极大的提升.官方的文档显示,PHP7可以达到PHP5.x版本两倍的性能.同时还对PHP的语法 ...

  3. day7-基础函数的学习(二)

    过了元旦,加油鸭,冲鸭!!! 闲话不说,开始今日份学习整理. 今日目录,今天的学习内容不是很多! 1.函数名的运用 2.闭包(重要) 3.迭代器(重要) 开始今日份总结 1.函数名的运用 1.1函数名 ...

  4. Qt License 解读

    对于桌面和移动平台应用 官方说明如下 Qt for Application Development lets you create applications for desktop and mobil ...

  5. Oracle 执行计划(三)-------表连接方式

    SQL FOR TESTING: create table qcb_student_test( student_id number, student_name varchar2(20), studen ...

  6. Winform开发框架中工作流模块的动态处理

    在工作流处理表中,首先我们区分流程模板和流程实例两个部分,这个其实就是类似模板和具体文档的概念,我们一份模板可以创建很多个类似的文档,文档样式结构类似的.同理,流程模板实例为流程实例后,就是具体的一个 ...

  7. SpringCloud(5)路由网关Spring Cloud Zuul

    一个简单的微服务系统如下图: 1.为什么需要Zuul Zuul很容易实现 负载均衡.智能路由 和 熔断器,可以做身份认证和权限认证,可以实现监控,在高流量状态下,对服务进行降级. 2.路由网关 继续前 ...

  8. 容器中的JVM资源该如何被安全的限制?

    前言 Java与Docker的结合,虽然更好的解决了application的封装问题.但也存在着不兼容,比如Java并不能自动的发现Docker设置的内存限制,CPU限制. 这将导致JVM不能稳定服务 ...

  9. JShell脚本工具

    JShell脚本工具是JDK9的新特性 什么时候会用到 JShell 工具呢,当我们编写的代码非常少的时候,而又不愿意编写类,main方法,也不愿意去编译和运行,这个时候可以使用JShell工具.启动 ...

  10. 菜鸟学习计划浅谈之Linux系统

    人这一生都是在不断地学习,不断地进步中度过的,刚开始学习任何一门知识的时候,我们都习惯性的称自己为菜鸟,觉得自己对这方面的知识欠缺,水平很low,我也是如此.但我擅长总结,对于自己学习的新知识,总结学 ...