CF Edu Round 71
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的更多相关文章
- CF Educational Round 78 (Div2)题解报告A~E
CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students 依题意模拟即可 #include<bits/stdc++.h> us ...
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
- CF Codeforces Round #231 (Div. 2)
http://codeforces.com/contest/394 话说这次CF做的超级不爽,A题一开始交过了,我就没再管,B题还没看完呢,就死困死困的,后来觉得B题枚举一下估计能行,当时是觉得可以从 ...
- rsa Round #71 (Div. 2 only)
Replace A Time limit: 1000 msMemory limit: 256 MB You are given a string SS containing only letter ...
- [题解向] CF#Global Round 1の题解(A $\to$ G)
这里是总链接\(Link\). \(A\) 题意:求\(\sum_{i=1}^{k} a_i\times b^{k-i}\)的奇偶性, \(k = \Theta(n \log n)\) --其实很容易 ...
- Educational Codeforces Round 71
https://www.cnblogs.com/31415926535x/p/11460682.html 上午没课,做一套题,,练一下手感和思维,,教育场的71 ,,前两到没啥,,后面就做的磕磕巴巴的 ...
- [cf]Codeforces Round #784(Div 4)
由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...
- 【做题笔记】CF Edu Round 132
1. 前言 本人第一次把 Div2. D 切了,开心. C 不会,寄. 后来在场外想到一种奇怪做法 AC 了. 2. 正文(A-D) CF 比赛链接 A. Three Doors 签到题.循环查找手中 ...
随机推荐
- 初始CSS01
CSS基础知识 CSS介绍 CSS全称为层叠样式表,与HTML相辅相成,实现网页的排版布局与样式美化. 使用方式 根据样式表在页面中呈现的方式不同,可以通过以下三种方式在页面中使用格式 内联样式 改样 ...
- 【Deeplearning.ai 】吴恩达深度学习笔记及课后作业目录
吴恩达深度学习课程的课堂笔记以及课后作业 代码下载:https://github.com/douzujun/Deep-Learning-Coursera 吴恩达推荐笔记:https://mp.weix ...
- 改善深层神经网络-week1编程题(Regularization)
Regularization Deep Learning models have so much flexibility and capacity that overfitting can be a ...
- 第31篇-方法调用指令之invokevirtual
invokevirtual字节码指令的模板定义如下: def(Bytecodes::_invokevirtual , ubcp|disp|clvm|____, vtos, vtos, invokevi ...
- BUAA 2020 软件工程 结对项目作业
Author: 17373051 郭骏 3.28添加:4.计算模块接口的设计与实现过程部分,PairCore实现的细节 项目 内容 这个作业属于哪个课程 2020春季计算机学院软件工程(罗杰 任健) ...
- 2021.9.28考试总结[NOIP模拟64]
T1 三元组 发现确定\(b,c\)的情况下,\(a\)的值域是连续的.确定\(b\)后\(a+b\)的取值是\([1+b,b+b]\).树状数组维护对每个\(b\)可行的\(c\). 注意取模后取值 ...
- 疯狂Java基础Day2
巩固Java流程控制的学习... 一.用户交互Scanner 通过Scanner类获取用户的输入 import java.util.Scanner; public class Demo1 { publ ...
- 同人逼死官方系列!从 DDC 嗅探器到 sddc_sdk_lib 的数据解析
从 DDC 嗅探器到 sddc_sdk_lib 的数据解析 之前的 DDC 协议介绍 主要讲了设备加入.退出以及维持设备状态,而 SDK框架 sddc_sdk_lib 解析 主要讲了 SDK 库的结构 ...
- Codeforces Round #744 (Div. 3) G题题解
淦,最后一道题没写出来,...还是我太菜了,不过这个题确实比较有趣. G. Minimal Coverage 简化题意:就是你处在坐标轴的0点上,给你一个序列\(a_i\),每次你可以选择向左走\(a ...
- mongodb安装教程(一)
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/fengtingYan/article/de ...