[Codeforces Global Round 14]
打挺差的。
不过\(C,D\)一眼秒了,大概是对这几个月努力的一个结果?
\(B\)玄学错误挂了两发。
脑子痛然后打到一半就去睡觉了。
————————————————————————————————————————————————
以上是闲话部分。
\(A\)
考虑判断是否存在一个前缀和不满足条件。
有后缀的话拉一个过来交换就行,否则就是没有方案。
A
// code by fhq_treap
#include<bits/stdc++.h>
#define ll long long
#define N 300005
inline ll read(){
char C=getchar();
ll A=0 , F=1;
while(('0' > C || C > '9') && (C != '-')) C=getchar();
if(C == '-') F=-1 , C=getchar();
while('0' <= C && C <= '9') A=(A << 1)+(A << 3)+(C - 48) , C=getchar();
return A*F;
}
struct P{
int to,next;
};
struct Map{
P e[N << 1];
int head[N],cnt;
Map(){
std::memset(head,0,sizeof(head));
cnt = 0;
}
inline void add(int x,int y){
e[++cnt].to = y;
e[cnt].next = head[x];
head[x] = cnt;
}
};
ll t;
ll num[N];
ll n,k;
int main(){
t = read();
while(t -- ){
n = read(),k = read();
ll sum = 0,s = 0;
for(int i = 1;i <= n;++i)
num[i] = read(),s += num[i];
if(s == k)
puts("NO");
else{
puts("YES");
for(int i = 1;i <= n;++i){
sum += num[i];
if(sum == k){
std::cout<<num[i + 1]<<" "<<num[i]<<" ";
++i;
}
else
std::cout<<num[i]<<" ";
}
puts("");
}
}
}
\(B\)
考虑基本单位是一个边长为\(1\)或\(sqrt(2)\)的单位正方形。
判断是否能有这样平方数个单位正方形。
玄学错误挂了两发,重写一下就过了,怪离谱的
B
// code by fhq_treap
#include<bits/stdc++.h>
#define ll long long
#define N 300005
inline ll read(){
char C=getchar();
ll A=0 , F=1;
while(('0' > C || C > '9') && (C != '-')) C=getchar();
if(C == '-') F=-1 , C=getchar();
while('0' <= C && C <= '9') A=(A << 1)+(A << 3)+(C - 48) , C=getchar();
return A*F;
}
struct P{
int to,next;
};
struct Map{
P e[N << 1];
int head[N],cnt;
Map(){
std::memset(head,0,sizeof(head));
cnt = 0;
}
inline void add(int x,int y){
e[++cnt].to = y;
e[cnt].next = head[x];
head[x] = cnt;
}
};
ll t;
int main(){
t = read();
while(t -- ){
ll x = read();
if(x % 2 == 0 && ((int)sqrt(x / 2) * (int)sqrt(x / 2) == x / 2))
puts("YES");
else{
if(x % 4 == 0 && ((int)sqrt(x / 4) * (int)sqrt(x / 4) == x / 4))
puts("YES");
else
puts("NO");
}
}
}
\(C\)
考虑题目的意思就是让这\(m\)组中最小的最大,最大的最小。
那么考虑派完序,一个接一个往这\(m\)组丢,具体实现看代码。
C
// code by fhq_treap
#include<bits/stdc++.h>
#define ll long long
#define N 300005
inline ll read(){
char C=getchar();
ll A=0 , F=1;
while(('0' > C || C > '9') && (C != '-')) C=getchar();
if(C == '-') F=-1 , C=getchar();
while('0' <= C && C <= '9') A=(A << 1)+(A << 3)+(C - 48) , C=getchar();
return A*F;
}
struct P{
int to,next;
};
struct Map{
P e[N << 1];
int head[N],cnt;
Map(){
std::memset(head,0,sizeof(head));
cnt = 0;
}
inline void add(int x,int y){
e[++cnt].to = y;
e[cnt].next = head[x];
head[x] = cnt;
}
};
ll t;
ll n,m,k;
ll s[N];
struct T{
ll id,v,to;
}num[N];
bool cmp1(T a,T b){
return a.v < b.v;
}
bool cmp2(T a,T b){
return a.id < b.id;
}
int main(){
t = read();
while(t -- ){
n = read(),m = read(),k = read();
for(int i = 1;i <= n;++i)
num[i].id = i,num[i].v = read();
std::sort(num + 1,num + n + 1,cmp1);
for(int i = 1;i <= m;++i)
s[i] = 0;
for(int i = 1;i <= n;++i)
s[(i % m) + 1] += num[i].v,num[i].to = (i % m) + 1;
ll minn = 0x3f3f3f3f,maxx = -0x3f3f3f3f;
for(int i = 1;i <= m;++i)
minn = std::min(minn,s[i]),maxx = std::max(maxx,s[i]);
if(maxx - minn <= k){
puts("YES");
std::sort(num + 1,num + n + 1,cmp2);
for(int i = 1;i <= n;++i)
std::cout<<num[i].to<<" ";
puts("");
}
else
puts("NO");
}
}
\(D\)
看出来如果\(l,r\)不相等,则一定要从多的一边向少的一边转变,那么这个时候尽量让能匹配的袜子多就行了。
D
// code by fhq_treap
#include<bits/stdc++.h>
#define ll long long
#define N 300005
inline ll read(){
char C=getchar();
ll A=0 , F=1;
while(('0' > C || C > '9') && (C != '-')) C=getchar();
if(C == '-') F=-1 , C=getchar();
while('0' <= C && C <= '9') A=(A << 1)+(A << 3)+(C - 48) , C=getchar();
return A*F;
}
struct P{
int to,next;
};
struct Map{
P e[N << 1];
int head[N],cnt;
Map(){
std::memset(head,0,sizeof(head));
cnt = 0;
}
inline void add(int x,int y){
e[++cnt].to = y;
e[cnt].next = head[x];
head[x] = cnt;
}
};
ll t,n,l,r;
ll c[N],lc[N],rc[N],cnt[N];
bool del[N];
int main(){
t = read();
while(t -- ){
n = read(),l = read(),r = read();
for(int i = 1;i <= n;++i)
c[i] = read(),lc[c[i]] = 0,rc[c[i]] = 0,cnt[c[i]] = 0,del[c[i]] = 0;
for(int i = 1;i <= l;++i)
lc[c[i]] ++ ,cnt[c[i]] ++ ;
for(int i = l + 1;i <= n;++i)
rc[c[i]] ++ ,cnt[c[i]] ++ ;
for(int i = 1;i <= l;++i)
if(rc[c[i]])
rc[c[i]] -- ,lc[c[i]] -- ,cnt[c[i]] -= 2;
ll need = abs(r - l) / 2;
if(l > r){
for(int i = 1;i <= l;++i){
while(need && lc[c[i]] >= 2)
lc[c[i]] -= 2,cnt[c[i]] -= 2,need -- ;
}
}else{
if(l < r){
for(int i = l + 1;i <= n;++i)
while(need && rc[c[i]] >= 2)
rc[c[i]] -= 2,cnt[c[i]] -= 2,need -- ;
}
}
ll ans = 0;
for(int i = 1;i <= n;++i){
if(!del[c[i]])
del[c[i]] = 1,ans += cnt[c[i]] ;
}
std::cout<<ans / 2 + abs(r - l) / 2<<std::endl;
}
}
\(E\)
数数题。
大概看出来一点东西。
不过连续的一段的操作自己不会算方案数。
后来补的。
考虑计\(f[i][j]\)为开到\(i\)台,\(j\)台为自己手动开的。
那么就是考虑连续一段(即这一段没有自动开的)的方案数了
长度为\(l\)的一段则必有选择一个\(i\),表示从他开始向两边扩展,则还有\(l - 1\)个位置,有\(i - 1\)个数要丢进去,考虑前\(i - 1\)个数一旦确定,则整个序列确定。
所以连续一段的答案是\(C_{l - 1}^0 + C_{l - 1}^1 ..... = 2^{l - 1}\)
所以\(f[i + k + 1][j + k] = f[i][j] * 2^{k - 1} * C_{j + k}^k\)
E
#include<iostream>
#include<cstdio>
#define ll long long
#define N 500
ll mod;
ll f[N][N];
ll n;
inline ll pow(ll a,ll b){
ll ans = 1;
while(b){
if(b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
ll s[N],inv[N];
inline ll c(ll a,ll b){
return s[a] * inv[a - b] % mod * inv[b] % mod;
}
ll ans = 0;
int main(){
scanf("%lld%lld",&n,&mod);
s[0] = 1;
for(int i = 1;i <= 405;++i)
s[i] = s[i - 1] * i % mod;
inv[405] = pow(s[405],mod - 2);
for(int i = 404;i >= 1;--i)
inv[i] = inv[i + 1] * (i + 1) % mod;
for(int i = 1;i <= n;++i)
f[i][i] = pow(2,i - 1);
for(int i = 1;i <= n;++i)
for(int j = 1;j <= i;++j)
for(int k = 1;i + k + 1 <= n;++k)
f[i + k + 1][j + k] = (f[i + k + 1][j + k] + f[i][j] * pow(2,k - 1) % mod * c(j + k,k) % mod) % mod;
for(int i = 1;i <= n;++i)
ans = (f[n][i] + ans) % mod;
std::cout<<ans<<std::endl;
}
\(F\)
果然这题好做很多?
虽然比赛的时候看了一眼就睡了。
后来补的。
很简单的一个构造就是了。
考虑两个点合在一起时把权值和边集都合在一起。
每次挑最大的点和周围一个点合并。
[Codeforces Global Round 14]的更多相关文章
- Codeforces Global Round 14 E. Phoenix and Computers
题目链接 点我跳转 题目大意 给定 \(N\) 台电脑,起初每台电脑都是关闭的 现在你可以随意打开电脑,但如果第 \(i-1\).第 \(i+1\) 台电脑是开启的,则第 \(i\) 台电脑也会自动开 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Beta Round #14 (Div. 2)
Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 A 找最大最小的行列值即可 #include<bits/s ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
随机推荐
- easyDialog 简单、实用的弹出层组件
easyDialog 简单.实用的弹出层组件 使用背景 在完成导师需求时,导师要求寻找比一个layer弹出层组件体积小得多的.最好能嵌入在进HTML代码中而非src引用的弹出层组件,在这个需求下,我找 ...
- IEEE754浮点数的转换
将十进制数转换为单精度浮点数 如何将十进制数转换为单精度浮点数参考 首先要知道 IEEE浮点标准:V=(-1)^s * M * 2^E 1.符号(sign)s决定这个数是负数(s=1)还是正数,0(s ...
- Spring中属性注入的几种方式以及复杂属性的注入详解
在spring框架中,属性的注入我们有多种方式,我们可以通过set方法注入,可以通过构造方法注入,也可以通过p名称空间注入,方式多种多样,对于复杂的数据类型比如对象.数组.List.Map.Prope ...
- [no code][scrum meeting] Beta 12
$( "#cnblogs_post_body" ).catalog() 例会时间:5月27日11:30,主持者:乔玺华 一.工作汇报 人员 昨日完成任务 明日要完成的任务 乔玺华 ...
- 【二食堂】Beta - Scrum Meeting 3
Scrum Meeting 3 例会时间:5.15 18:30~18:50 进度情况 组员 当前进度 今日任务 李健 1. 继续完成文本区域划词添加的功能 issue 1. 划词功能已经实现,继续开发 ...
- 热身训练1 Blood Cousins Return
点此看题 简要题面: 一棵树上有n个节点,每个节点有对应的名字(名字可重复). 每次询问,求深度比$vi$多$ki$的$vi$的儿子中,有多少种名字 分析: Step1: 我们可以懂$DFS$轻松找到 ...
- C语言链表实例--玩转链表
下图为最一简单链表的示意图: 第 0 个结点称为头结点,它存放有第一个结点的首地址,它没有数据,只是一个指针变量.以下的每个结点都分为两个域,一个是数据域,存放各种实际的数据,如学号 num,姓名 n ...
- C++构造函数注意事项
1.匿名对象 首先应该明确匿名对象,匿名对象是之没有对象名,调用完构造函数后即析构的对象.下面通过代码捕捉类的构造函数和析构函数,以进行说明: #include <iostream> us ...
- JAVA笔记 **__Netbeans常用快捷键
sout + Tab 生成输出语句 alt+shift+F 格式化代码 Alt+insert 插入代码(包括构造函数,setter和getter方法等) Ctrl+O或Ctrlt+单击 转 ...
- 解决CentOS添加新网卡后找不到网卡配置文件,配置多网卡并设置静态路由
参考文章 https://blog.csdn.net/qq_36512792/article/details/79787649 使用VMware Workstation虚拟机安装好CentOS7虚拟机 ...