CF Edu Round 71

A There Are Two Types Of Burgers

贪心随便模拟一下

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAXN 200006
int n , m;
int A[MAXN];
int b , p , f , h , c;
int main() {
int T;cin >> T;
while( T-- ) {
cin >> b >> p >> f >> h >> c;
int res = 0;
if( h > c ) {
if( b > 2 * p ) b -= 2 * p , res += p * h;
else { printf("%d\n",( b / 2 ) * h); continue; }
if( b > 2 * f ) printf("%d\n",res + f * c);
else printf("%d\n", res + ( b / 2 ) * c);
} else {
if( b > 2 * f ) b -= 2 * f , res += f * c;
else { printf("%d\n",( b / 2 ) * c); continue; }
if( b > 2 * p ) printf("%d\n",res + p * h);
else printf("%d\n", res + ( b / 2 ) * h);
}
}
}

B Square Filling

贪心,从左上角往左往下枚举,如果可以涂就涂,最后判断一下就好了。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
#define MAXN 56
int A[MAXN][MAXN];
int n , m;
bool book[MAXN][MAXN];
vector<pair<int,int> > ans;
int main() {
cin >> n >> m;
for( int i = 1 ; i <= n ; ++ i )
for( int j = 1 ; j <= m ; ++ j ) scanf("%d",&A[i][j]);
for( int i = 1 ; i <= n ; ++ i ) {
for( int j = 1 ; j <= m ; ++ j ) if( A[i][j] ) {
if( ( i == n || j == m ) ) if(!book[i][j]){ return puts("-1") , 0; } else continue;
if( A[i][j] == 1 && A[i + 1][j] == 1 && A[i + 1][j + 1] == 1 && A[i][j + 1] == 1 )
book[i][j] = book[i+1][j] = book[i+1][j+1] = book[i][j + 1] = 1 , ans.push_back( make_pair( i , j ) );
else if( !book[i][j] ) return puts("-1") , 0;
}
}
cout << ans.size() << endl;
for( int i = 0 ; i < ans.size() ; ++ i )
printf("%d %d\n",ans[i].first , ans[i].second);
}

C Gas Pipeline

随便线性dp一下就好了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAXN 300006
#define int long long
typedef long long ll;
using namespace std;
ll dp[MAXN][2] , len;
char s[MAXN];
signed main() {
int T; cin >> T;
while( T --> 0 ) {
ll n, a, b;
scanf("%lld%lld%lld%s", &n, &a, &b , s);
len = strlen(s);
dp[0][0] = b, dp[0][1] = 0x3f3f3f3f3f3f3f3f;
for (int i = 1; i <= len; i++)
if (s[i - 1] == '1')
dp[i][1] = dp[i - 1][1] + a + 2 * b , dp[i][0] = 0x3f3f3f3f3f3f3f3f;
else
dp[i][1] = min( ( a << 1 ) + dp[i - 1][0], dp[i - 1][1] + a) + ( b << 1 ),
dp[i][0] = min( a + dp[i - 1][0] , ( a << 1 ) + dp[i - 1][1] ) + b;
printf("%lld\n",dp[len][0]);
}
}

D Number Of Permutations

容斥一下,总排列数 - 第一个顺序 - 第二个顺序 + 两个都顺序

计算很简单,用阶乘搞一下就好了

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define P 998244353
#define MAXN 300006
#define int long long
int n;
pair<int,int> A[MAXN];
int J[300050];
bool cmp1(pair<int,int> a,pair<int,int> b) {
return a.first == b.first ? a.second < b.second : a.first < b.first;
}
bool CMP(pair<int,int> a,pair<int,int> b) {
return a.second < b.second;
}
signed main() {
J[0] = 1; for (int i = 1; i <= 300000; ++i) J[i] = J[i - 1] * 1ll * i % P;
scanf("%lld", &n);
for (int i = 1; i <= n; ++i)
scanf("%lld%lld", &A[i].first, &A[i].second);
sort(A + 1, A + 1 + n, cmp1);
int cur = 1 , ans = J[n];
int l = 0;
for (int i = 1; i <= n; ++i)
if (A[i].first != A[i - 1].first) cur *= J[l], l = 1, cur %= P;
else l++;
cur *= J[l] , cur %= P , ans -= cur;
bool flg = 1;
for (int i = 1; i <= n; ++i)
if (A[i].second < A[i - 1].second) { flg = 0; break; }
if (flg) {
cur = 1 , l = 0;
for (int i = 1; i <= n; ++i)
if (A[i].first != A[i - 1].first || A[i].second != A[i - 1].second)
cur *= J[l], l = 1 , cur %= P;
else l++;
cur *= J[l], cur %= P , ans += cur;
}
sort(A + 1, A + 1 + n, CMP);
cur = 1, l = 0;
for (int i = 1; i <= n; ++i) {
if (A[i].second != A[i - 1].second)
cur *= J[l] , cur %= P , l = 1;
else ++ l;
}
cur *= J[l] , cur %= P , ans -= cur;
printf("%lld\n", (ans % P + P) % P);
return 0;
}

E XOR Guessing

考场上嫖了个ywh的随机。。。

然而实际上很简单。。

考虑分成前7位和后7位,前100个数字前7位全部留空,后100个数字后7位全部留空,做完了

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
using namespace std;
int pre , aft;
int main() {
cout << '?' ;
for( int i = 1 ; i <= 100 ; ++ i ) cout << ' ' << i;
cout << endl;
fflush( stdout );
cin >> pre;
cout << '?';
for( int i = 1 ; i <= 100 ; ++ i ) cout << ' ' << ( i << 7 );
cout << endl;
fflush( stdout );
cin >> aft;
int res = 0;
res |= ( pre & ( ( 1 << 8 ) - 1 ) << 7 );
res |= ( aft & ( 1 << 7 ) - 1 );
cout << '!' << ' ' << res << endl;
fflush( stdout );
}

F Remainder Problem

大水题

第二种操作,如果$ y > \sqrt n $ 直接naive地暴力

否则,每次一操作后预处理一下 $ y \leq \sqrt n $的答案

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
typedef long long ll;
using namespace std;
#define MAXN 500006
#define MXBL 730
int t, x, y;
ll buc[MAXN] , S[MXBL][MXBL] , res ;
signed main() {
int T;cin >> T;
while( T --> 0 ) {
scanf("%d%d%d", &t, &x, &y);
if (t != 1) {
if (x < MXBL ) printf("%lld\n", S[x][y]);
else {
res = 0; for (int j = y; j < MAXN; j += x) res += buc[j];
printf("%lld\n", res);
}
} else {
for (int j = 1; j < MXBL; ++j) S[j][x % j] += y;
buc[x] += y;
}
}
}

G Indie Album

ACAM 好题

其实自己根本不怎么会acam。。。这题赛后写来顺便学习了一下acam

当然,考场上很多人都写的广义后缀自动机+树链剖分。

只是yijan现在还不大会(。。。wtcl

发现后缀自动机各种板子写多了的带佬们看字符串题都是秒啊。。


首先对于所有询问串建ac自动机,再把fail树建立出来。

如果不考虑复杂度,把询问离线,然后对于每一个文本串都在询问的fail树上跑,跑到的节点都+1,然后每个询问在这个串里面出现的次数就是这个串子树的和。

但是这么做显然复杂度是错的,但是发现这道题给文本串的方式很特殊,所有的文本串也构成了一个树形结构,于是可以考虑dfs这个文本串构成的树,用一种类似增量法的科技,增加一个字符后会多对一个位置+1,而离开dfs时会对这个位置-1,中间统计一下所有关于这个串的答案就可以了。

单点+,区间查需要一个fenwick tree,复杂度 \(O (TlogT)\)

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define MAXN 400006
int n , m;
char ch[MAXN];
 
int trie[MAXN][26] , fail[MAXN * 26] , ncnt = 0;
int T[MAXN];
int dfn;
void add( int x , int c ) {
while( x <= dfn ) T[x] += c , x += x & -x;
}
int que( int x ) {
int ret = 0;
while( x > 0 ) ret += T[x] , x -= x & -x;
return ret;
}
vector< pair<int,int> > ff[MAXN];
int ins( char* P ) {
int cur = 0 , len = strlen( P );
for( int i = 0 ; i < len ; ++ i ) {
int v = P[i] - 'a';
if( !trie[cur][v] ) trie[cur][v] = ++ncnt;
cur = trie[cur][v];
}
return cur;
}
queue<int> Q;
vector<int> F[MAXN] , G[MAXN];
void build( ) {
int cur;
for( int i = 0 ; i < 26 ; ++ i ) if( trie[0][i] )
Q.push( trie[0][i] ) , fail[trie[0][i]] = 0;
while( !Q.empty( ) ) {
cur = Q.front() , Q.pop();
F[fail[cur]].push_back( cur );
for( int i = 0 ; i < 26 ; ++ i ) {
if( trie[cur][i] )
fail[trie[cur][i]] = trie[fail[cur]][i] ,
Q.push( trie[cur][i] );
else
trie[cur][i] = trie[fail[cur]][i];
}
}
}
int L[MAXN] , R[MAXN];
void predfs( int u ) {
L[u] = ++ dfn;
for( int i = 0 ; i < F[u].size() ; ++ i ) predfs( F[u][i] );
R[u] = dfn;
}
int ans[MAXN];
void work( int u , int p ) {
p = trie[p][ch[u] - 'a'];
add( L[p] , 1 );
for( int i = 0 ; i < G[u].size() ; ++ i )
work( G[u][i] , p );
for( int i = 0 ; i < ff[u].size() ; ++ i )
ans[ff[u][i].second] = que( R[ff[u][i].first] ) - que( L[ff[u][i].first] - 1 );
add( L[p] , -1 );
}
char P[MAXN];
int ffa[MAXN];
int main() {
cin >> n;
for( int i = 1 , t , opt ; i <= n ; ++ i ) {
scanf("%d ",&opt);
if( opt == 1 ) { scanf("%c",&ch[i]) , ffa[i] = 0 , G[0].push_back( i ); continue; }
scanf("%d %c",&t,&ch[i]);
ffa[i] = t , G[t].push_back( i );
getchar();
}
cin >> m;
for( int i = 1 , t ; i <= m ; ++ i ) {
scanf("%d%s",&t,P);
int x = ins( P );
ff[t].emplace_back( make_pair( x , i ) );
}
build( );
predfs( 0 );
for( int i = 1 ; i <= n ; ++ i ) if( !ffa[i] )
work( i , 0 );
for( int i = 1 ; i <= m ; ++ i ) printf("%d\n",ans[i]);
}

CF Edu Round 71的更多相关文章

  1. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  2. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  3. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

  4. CF Codeforces Round #231 (Div. 2)

    http://codeforces.com/contest/394 话说这次CF做的超级不爽,A题一开始交过了,我就没再管,B题还没看完呢,就死困死困的,后来觉得B题枚举一下估计能行,当时是觉得可以从 ...

  5. rsa Round #71 (Div. 2 only)

    Replace A Time limit: 1000 msMemory limit: 256 MB   You are given a string SS containing only letter ...

  6. [题解向] CF#Global Round 1の题解(A $\to$ G)

    这里是总链接\(Link\). \(A\) 题意:求\(\sum_{i=1}^{k} a_i\times b^{k-i}\)的奇偶性, \(k = \Theta(n \log n)\) --其实很容易 ...

  7. Educational Codeforces Round 71

    https://www.cnblogs.com/31415926535x/p/11460682.html 上午没课,做一套题,,练一下手感和思维,,教育场的71 ,,前两到没啥,,后面就做的磕磕巴巴的 ...

  8. [cf]Codeforces Round #784(Div 4)

    由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...

  9. 【做题笔记】CF Edu Round 132

    1. 前言 本人第一次把 Div2. D 切了,开心. C 不会,寄. 后来在场外想到一种奇怪做法 AC 了. 2. 正文(A-D) CF 比赛链接 A. Three Doors 签到题.循环查找手中 ...

随机推荐

  1. 【二食堂】Alpha - 测试报告

    TextMarking Alpha阶段测试报告 前后端测试过程及结果 在Alpha阶段,测试工作紧跟后端开发进度,一下是我们所做的一些测试工作. 后端单元测试 测试代码可以在git仓库中查看,后端对所 ...

  2. oo第四次博客-UML暨学期总结

    一. 本单元两次作业架构设计 这两次作业实际上难度不大,不存在算法上的难题,大部分时间都是用在处理UML图中各个元素的关系上. 第一次UML主要处理UML类图.有UMLclass,UMLinterfa ...

  3. TensorFlow从入门到入坑(1)

    初识TensorFlow 一.术语潜知 深度学习:深度学习(deep learning)是机器学习的分支,是一种试图使用包含复杂结构或由多重非线性变换构成的多个处理层对数据进行高层抽象的算法. 深度学 ...

  4. c#复制数组的多种方法

    方法一:使用for循环 int []pins = {9,3,7,2} int []copy = new int[pins.length]; for(int i =0;i!=copy.length;i+ ...

  5. vue打包后反编译到源代码(reverse-sourcemap)

    因为突然的疫情把我困在家了,家里的电脑没有源代码,但是需求还要改,工作还得继续... 从服务器下载了之前上传的打包后的文件,找了一圈反编译方法,得救了,在此记录一下. 1.npm install -- ...

  6. 绚丽的色彩从何而来_LOTO示波器实测WS2812B系LED光源

    绚丽的色彩从何而来_LOTO示波器实测WS2812B系LED光源 不管你对 "RGB性能狂升300%" 的梗认同不认同,不可否认,绚丽的彩色很是酷炫,在现在市面上带"灯& ...

  7. 创建双向 CA x509 验证证书 kube-apiserver

    1. 设置 kube-apiserver 的 CA 证书相关的文件和启动参数 使用 OpenSSL 工具在 Master 服务器上创建 CA 证书和私钥相关的文件: # openssl genrsa ...

  8. Vue&Element开发框架中增加工作流处理,工作流的各个管理页面的界面处理

    我在起前面的几篇随笔中,大概介绍了工作流的一些场景化处理,包括如何把具体业务表单组件化,并在查看和编辑界面中,动态加载组件内容,以及对于查看申请单的主页面,把审批.取消.发起会签.会签.批示分阅.阅办 ...

  9. Discovery直播 | 3D“模”术师,还原立体世界——探秘3D建模服务

    通过多张普通的照片重建一个立体逼真的3D物体模型,曾经靠想象实现的事情,现在, 使用HMS Core 3D建模服务即可实现! 3D模型作为物品在数字世界中的孪生体,用户可以自己拍摄.建模并在终端直观感 ...

  10. uni-app map组件关于marker标记点动态设置的问题

    marker是Array类型,赋值的时候只能对整个数组进行更改赋值,不能只改变内部的对象,亲测Vue.$set()也不行 this.marker = [ { latitude: 39.90, long ...