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 ...
随机推荐
- linux命令之用户和用户组
知识点: 1.-rwx--x--x (711) 只有所有者才有读,写,执行的权限,组群和其他人只有执行的权限 2.将root用户添加到supergroup用户组 groupadd supergroup ...
- 安装autoit libary失败问题解决
运行环境:win7-32,python2.7安装遇到的问题:
- JS 构造图片Image对象
var image=new Image(); image.src=""; console.log(image.width);
- AVL树与红黑树
平衡树是平时经常使用数据结构. C++/JAVA中的set与map都是通过红黑树实现的. 通过了解平衡树的实现原理,可以更清楚的理解map和set的使用场景. 下面介绍AVL树和红黑树. 1. AVL ...
- log4j和commons- logging(好文整理转载)
一 :为什么同时使用commons-logging和Log4j?为什么不仅使用其中之一? Commons-loggin的目的是为 “所有的Java日志实现”提供一个统一的接口,它自身的日志功能平常弱( ...
- log4j 设置将生成的日志进行gz压缩并删除过期日志
1.准备jar :log4j-1.2.17.jar,commons-logging-1.2.jar,这2个就可以了,其他关于日志的jar包就不要加进来了,在优先级上会有冲突. 2.定义一个类,继承R ...
- js判断浏览器是否安装Flash插件,并提示安装或开启
var flashChecker = function() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版本 if(do ...
- aliyun oss 文件上传 java.net.SocketTimeoutException Read timed out 问题分析及解决
upload ClientException Read timed out com.aliyun.openservices.ClientException: Read timed out ...
- Zabbix邮件告警提示Couldn't resolve host name解决办法
zabbix设置好邮件告警,当有触发时邮件未发送 查看zabbix server日志,提示不能连接邮件发送服务器,但是ping是可以通的
- Django - Jsonp、CORS
一.同源策略 https://www.cnblogs.com/yuanchenqi/articles/7638956.html 同源策略(Same origin policy)是一种约定,它是浏览器最 ...