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 ...
随机推荐
- laravel 控制器构造方法注入request对象
IndexController: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\ ...
- centos6 安装 directAdmin
注:教程参考 https://bbs.aliyun.com/read/159390.html 这篇文章来操作就可以了 需要注意的地方是 1)directAdmin 需要一个纯净的环境,安装direct ...
- pow()
pow() 如果接收两个参数,如 pow(x, y),则结果相当于 x**y,也就是 x 的 y 次方pow() 如果接收三个参数,如 pow(x, y, z),则结果相当于 (x**y) % z,也 ...
- Oracle函数的使用
日期转换to_date insert into test (birthday,name) values (to_date('2016-03-12','yyyy-mm-dd'),'zy'); to_ch ...
- discuz x 系列目录结构说明
api ┄┄┄外部接口 connect ┄┄┄腾讯互联 db ┄┄┄UCenter数据库备份接口 google ┄┄┄Google引擎使用 javascript ┄┄┄数据和广告的 J ...
- 谷歌Volley网络框架讲解——第一篇
自从公司新招了几个android工程师后,我清闲了些许.于是就可以有时间写写博客,研究一些没来的研究的东西. 今年的谷歌IO大会上,谷歌推出了自己的网络框架——Volley.不久前就听说了但是没有cl ...
- 【PHP】算法进阶,获取给定值的最优组合:虚拟币抵扣问题解决方案
商城里边.虚拟币抵扣问题解决方案 虚拟币抵扣规则,按照以下规则执行: 1.如果一个订单包含多款商品,且均支持虚拟币抵扣时: 优先按照最大化使用虚拟币进行全额抵扣原则进行抵扣,若抵扣后用户虚拟币账号 ...
- 网络子系统45_ip协议tos处理
//ip报头tos字段,一个字节 // 二进制位:[0 1 2] [3] [4] [5] [6] [7] // 1.[0 1 2] 表示优先级: // 000 路由 // 001 优先级 // 010 ...
- Android 生成分享长图并且添加全图水印
转载自 : http://blog.csdn.net/gengqiquan/article/details/65938021 领导最近觉得携程的截屏生成长图分享效果比较好,所以我们也加了个:产品觉得分 ...
- 【BZOJ4418】[Shoi2013]扇形面积并 扫描线+线段树
[BZOJ4418][Shoi2013]扇形面积并 Description 给定N个同心的扇形,求有多少面积,被至少K个扇形所覆盖. Input 第一行是三个整数n,m,k.n代表同心扇形的个数,m用 ...