[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题秒出思 ...
随机推荐
- WPF 排版基础
一.WPF 排版基础 WPF使用控制面板来进行排版,控制面板实际上是一种可以放入WPF界面元素的容器.当用户把界面元素放入控制面板后,WPF会自动把这些界面元素放在它认为合适的地方.WPF开发人员需要 ...
- 异常大讨论-抛出异常还是返回false
iteye精华帖之异常大讨论 原帖链接http://www.iteye.com/topic/2038 Robbin的观点 观点1:Exception实际上代表了一个UseCase中的异常流的处理. 绝 ...
- Charles的简单用法
Charles的简单用法 一.抓电脑上 http 包 二.显示请求的 Request 和 Response 三.抓取电脑上 https 包 1.安装根证书 2.在钥匙串中启用根证书 3.配置哪些需要抓 ...
- Noip模拟34 2021.8.9
T1 Merchant 一眼二分,然后想了想维护凸包,好像并没有什么关系, 然后又想了想维护一个栈,发现跳指针细节过多不想打 最后直接打了二分,大点跑的飞快,感觉比较稳,出来$78$分 是没用神奇的$ ...
- Netty:Netty的介绍以及它的核心组件(三)—— 事件和ChannelHandler
Netty 使用异步事件驱动(Asynchronous Event-Driven)的应用程序范式,因此数据处理的管道(ChannelPipeLine)是经过处理程序(ChannelHandler)的事 ...
- 页表 Page tables
逻辑地址与物理地址的转化 页表是由页表项(PTE)组成的数组.512个PTE构成一个页表页(Page-table page). PTE中包含了物理页码(PPN physical page number ...
- valid-palindrome leetcode C++
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- JAVA笔记1__基本数据类型/输入输出/随机数/数组
/**八种基本数据类型 boolean byte short int long char float double */ public class test1{ public static void ...
- Forest v1.5.12 发布,声明式 HTTP 框架,已超过 1.6k star
Forest介绍 Forest 是一个开源的 Java HTTP 客户端框架,它能够将 HTTP 的所有请求信息(包括 URL.Header 以及 Body 等信息)绑定到您自定义的 Interfac ...
- Spring源码学习之容器的基本实现(一)
前言 最近学习了<<Spring源码深度解析>>受益匪浅,本博客是对学习内容的一个总结.分享,方便日后自己复习或与一同学习的小伙伴一起探讨之用. 建议与源码配合使用,效果更嘉, ...