Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution
A. Kitchen Utensils
Water.
#include <bits/stdc++.h>
using namespace std; #define N 110
int n, k, cnt[N]; int main()
{
while (scanf("%d%d", &n, &k) != EOF)
{
memset(cnt, , sizeof cnt);
for (int i = , x; i <= n; ++i)
{
scanf("%d", &x);
++cnt[x];
}
int Max = ;
for (int i = ; i <= ; ++i) Max = max(Max, cnt[i] % k == ? cnt[i] / k : cnt[i] / k + );
int res = ;
for (int i = ; i <= ; ++i) if (cnt[i])
{
res += Max * k - cnt[i];
}
printf("%d\n", res);
}
return ;
}
B. Personalized Cup
Water.
#include <bits/stdc++.h>
using namespace std; #define INF 0x3f3f3f3f
#define N 110
int pos[N], w[N], h[N], n;
string s; void init()
{
memset(w, 0x3f, sizeof w);
memset(h, 0x3f, sizeof h);
memset(pos, -, sizeof pos);
for (int i = ; i >= ; --i)
{
for (int j = ; j <= i; ++j) if (i % j == )
{
int a = i / j, b = j;
if (a > b) swap(a, b);
if (a <= && b <= && a <= w[i])
{
pos[i] = i;
w[i] = a;
h[i] = b;
}
if (w[i + ] < w[i])
{
pos[i] = pos[i + ];
w[i] = w[i + ];
h[i] = h[i + ];
}
}
}
} int main()
{
init();
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
while (cin >> s)
{
n = s.size();
cout << w[n] << " " << h[n] << "\n";
int need = pos[n] - n;
int must = need / w[n];
int remind = need % w[n];
for (int i = , pos = ; i <= w[n]; ++i)
{
int j = ;
for (; j <= must; ++j) cout << "*";
if (remind) cout << "*", ++j, --remind;
for (; j <= h[n]; ++j) cout << s[pos++];
cout << "\n";
}
}
return ;
}
C. Playing Piano
Upsolved.
思路:每一位枚举,记忆化搜索。$dp[i][j] 表示第i位放j是否可以$
#include <bits/stdc++.h>
using namespace std; #define N 100010
int n, a[N], res[N], dp[N][]; int DFS(int i, int num)
{
if (i > n) return ;
int &x = dp[i][num];
if (x != -) return x;
if (a[i] > a[i - ])
{
for (int j = num + ; j <= ; ++j)
{
x = DFS(i + , j);
if (x) return res[i] = j, x = ;
}
}
else if (a[i] < a[i - ])
{
for (int j = ; j < num; ++j)
{
x = DFS(i + , j);
if (x) return res[i] = j, x = ;
}
}
else
{
for (int j = ; j <= ; ++j) if (j != num)
{
x = DFS(i + , j);
if (x) return res[i] = j, x = ;
}
}
return x = ;
} int main()
{
while (scanf("%d", &n) != EOF)
{
memset(dp, -, sizeof dp);
a[] = ;
for (int i = ; i <= n; ++i) scanf("%d", a + i);
if (DFS(, )) for (int i = ; i <= n; ++i) printf("%d%c", res[i], " \n"[i == n]);
else puts("-1");
}
return ;
}
D. Barcelonian Distance
Solved.
题意:
在一个二维平面中,有一条直线,有两点个点,只能走这条直线上或者方格线上,求两点最短路径
思路:
考虑每个点到直线上通过方格线走只有两种方式,即横着走,纵着走
那么通过直线的方式即有四种
还有一种直接是曼哈顿距离,取$Min$即可
#include <bits/stdc++.h>
using namespace std; #define ll long long
const double eps = 1e-;
ll a, b, c, x[], y[];
double xa[], ya[], xb[], yb[]; double dis(double x1, double y1, double x2, double y2)
{
return sqrt((x1 - x2) * (x1 - x2) * 1.0 + (y1 - y2) * (y1 - y2) * 1.0);
} double calcx(ll y)
{
return -(b * y + c) * 1.0 / a;
} double calcy(ll x)
{
return -(a * x + c) * 1.0 / b;
} int main()
{
while (scanf("%lld%lld%lld", &a, &b, &c) != EOF)
{
for (int i = ; i < ; ++i) scanf("%lld%lld", x + i, y + i);
double res = abs(x[] - x[]) + abs(y[] - y[]);
xa[] = x[]; ya[] = calcy(x[]);
xa[] = calcx(y[]); ya[] = y[];
xb[] = x[]; yb[] = calcy(x[]);
xb[] = calcx(y[]); yb[] = y[];
for (int i = ; i < ; ++i)
{
for (int j = ; j < ; ++j)
{
res = min(res, dis(x[], y[], xa[i], ya[i]) + dis(x[], y[], xb[j], yb[j]) + dis(xa[i], ya[i], xb[j], yb[j]));
}
}
printf("%.15f\n", res);
}
return ;
}
E. The Unbearable Lightness of Weights
Upsolved.
题意:
有n个砝码,知道所有砝码的重量,但是不知道每个砝码和重量的对应关系,可以有一次询问,问用k个砝码组成总重量为m的方案,求最后你最多知道多少个砝码的具体重量
思路:
如果不同重量的砝码种类不超过2,直接输出n
01背包求出拼成重量为w, 物品个数为k的方案数,然后对于每种重量的砝码枚举个数,当且仅当当前个数和数量只有唯一一种方式组成时,那么这个数量就是合法的,可以用来更新答案
#include <bits/stdc++.h>
using namespace std; #define N 110
int n, sum, tot, a[N], dp[N * N][N], cnt[N], C[N][N]; void init()
{
for (int i = ; i <= ; ++i) for (int j = ; j <= i; ++j)
{
if (j == || j == i) C[i][j] = ;
else C[i][j] = C[i - ][j - ] + C[i - ][j];
}
} void Run()
{
init();
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i)
{
scanf("%d", a + i), sum += a[i], ++cnt[a[i]];
if (cnt[a[i]] == ) ++tot;
}
if (tot <= )
{
printf("%d\n", n);
continue;
}
dp[][] = ;
for (int i = ; i <= n; ++i)
{
for (int j = sum; j >= a[i]; --j) for (int k = ; k <= n; ++k)
dp[j][k] += dp[j - a[i]][k - ];
}
int res = ;
for (int i = ; i <= ; ++i) if (cnt[i])
{
for (int j = ; j <= cnt[i]; ++j)
{
if (dp[i * j][j] == C[cnt[i]][j])
res = max(res, j);
}
}
printf("%d\n", res);
}
} int main()
{
#ifdef LOCAL
freopen("Test.in", "r", stdin);
#endif Run();
return ;
}
F. Vasya and Maximum Matching
Unsolved.
G. Chattering
Unsolved.
Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution的更多相关文章
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano
题意:给出一个数列 a1 a2......an 让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i) 那么b( ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)
题意:给出一条直线 ax +by+c=0 给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及 给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path
http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)
https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】
任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...
随机推荐
- swift - 之 UIColor使用自定义的RGB配色
1.10进制颜色 UIColor(red: /, green: /, blue: /, alpha: 0.5) 2.16进制颜色 UIColor(red: , green: , blue: , alp ...
- BigDecimal类(精度计算类)的加减乘除
BigDecimal类 对于不需要任何准确计算精度的数字可以直接使用float或double,但是如果需要精确计算的结果,则必须使用BigDecimal类,而且使用BigDecimal类也可以进行大数 ...
- docker学习-docker核心技术
镜像:集装箱 ---build 仓库:超级码头 ----ship 容器:运行程序的地方 ----run docker运行一个程序的过程:去仓库把镜像拉到本地,然后用一条命令把镜像运行起 ...
- 【PHP】算法: 获取满足给定值的最优组合
PHP 获取给定值的最优组合 方法 - (蓝洛提供,博客地址: www.zhaorui.info) <?php ini_set('error_reporting','E_ALL^E_NOTI ...
- JS-简单地匀速运动框架
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 部署软件RDMA的步骤
date: 2018-08-28 19:46:56 参考原文原文:http://corasql.blog.51cto.com/5908329/1930455 ...
- 【BZOJ3012】[Usaco2012 Dec]First! Trie树+拓补排序
[BZOJ3012][Usaco2012 Dec]First! Description Bessie has been playing with strings again. She found th ...
- WCF(四) 绑定
绑定 是一个制定好的通道栈,包含了协议通道,传输通道和编码器.从功能上来看,一个绑定集成了通信模式.可靠性.安全性.事务传播和互操作性 绑定方式分两种:代码中和配置文件中绑定 1: 2: 3.配置ap ...
- 详解Javascript中prototype属性
转自:https://www.jb51.net/article/91826.htm 在典型的面向对象的语言中,如java,都存在类(class)的概念,类就是对象的模板,对象就是类的实例.但是在Jav ...
- RMAN备份详解
1.7.1数据库备份与RMAN备份的概念 1.数据库完全备份:按归档模式分为归档和非归档 归档模式 打开状态,属于非一致性备份 关闭状态,可以分为一致性和非一致性 非归档模式 打开状态,非一致性备份无 ...