codeforces-1141 (div3)
A.算2,3的因子个数即可
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int main(){
Sca2(N,M);
if(M % N){
puts("-1");
return ;
}
M /= N;
int ans = ;
while(!(M % )){
M /= ; ans++;
}
while(!(M % )){
M /= ; ans++;
}
if(M != ) ans = -;
Pri(ans);
return ;
}
A
B.复制成两倍长找最长连续1
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 5e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn];
int main(){
Sca(N);
for(int i = ; i <= N ; i ++) a[i] = a[i + N] = read();
N <<= ;
int cnt = ;
int ans = ;
for(int i = ; i <= N ; i ++){
if(a[i]){
cnt++;
ans = max(ans,cnt);
}else{
cnt = ;
}
}
Pri(ans);
return ;
}
B
C.设第一个数字为x,算前缀和pre可知a[i] = x + pre[i],找pre[i]最小的位置即为1的位置,可推知整个数组
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 5e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
LL a[maxn];
bool vis[maxn];
bool check(LL x){
if( > x || x > N) return false;
if(vis[x]) return false;
vis[x] = ;
return true;
}
int main(){
Sca(N);
a[] = ;
LL Min = ;
for(int i = ; i <= N ; i ++){
Scl(a[i]);
a[i] += a[i - ];
Min = min(Min,a[i]);
}
a[] = - Min;
bool flag = ;
if(!check(a[])) flag = ;
for(int i = ; i <= N && flag; i ++){
a[i] += a[];
if(!check(a[i])) flag = ;
}
if(!flag) puts("-1");
else for(int i = ; i <= N ; i ++) cout << a[i] << " ";
return ;
}
C
D.贪心,存下第一个字符串,第二个字符串的小写字母能直接匹配就匹配,不能匹配就匹配问号,最后将第二字符串的问号匹配第一个字符串落单的
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
vector<int>Q[];
vector<int>P;
char str1[maxn],str2[maxn];
vector<PII>ans;
int main(){
Sca(N);
scanf("%s%s",str1 + ,str2 + );
for(int i = ; i <= N ; i ++){
if(str1[i] == '?') Q[].pb(i);
else Q[str1[i] - 'a'].pb(i);
}
for(int i = ; i <= N ; i ++){
if(str2[i] == '?') P.pb(i);
else{
if(!Q[str2[i] - 'a'].empty()){
ans.pb(mp(Q[str2[i] - 'a'].back(),i));
Q[str2[i] - 'a'].pop_back();
}else if(!Q[].empty()){
ans.pb(mp(Q[].back(),i));
Q[].pop_back();
}
}
}
for(int i = ; i < && !P.empty(); i ++){
while(!P.empty() && !Q[i].empty()){
ans.push_back(mp(Q[i].back(),P.back()));
P.pop_back(); Q[i].pop_back();
}
}
Pri(ans.size());
for(int i = ; i < ans.size(); i ++){
printf("%d %d\n",ans[i].fi,ans[i].se);
}
return ;
}
D
E.求个前缀和,记录下最小前缀和和整个数组的和.
难点在于求会经过几个完整的回合才会遇到最终死的那个回合,这里用了倍增的方法处理,但我觉得显然可以用一个式子直接计算,只是因为我菜没想到
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
LL H;
LL a[maxn];
LL pre[maxn];
int main(){
Scl(H); Sca(N);
LL Min = 1e18;
for(int i = ; i <= N ; i ++){
Scl(a[i]);
pre[i] = pre[i - ] + a[i];
Min = min(Min,pre[i]);
}
if(H + Min > && pre[N] >= ){
puts("-1");
return ;
}
LL ans = ;
if(H + Min > ){
LL x = ;
while(pre[N] * x + H + Min > ){
x *= ;
}
x /= ;
for(LL i = x; i > ; i /= ){
while(pre[N] * i + H + Min > ){
H += pre[N] * i;
ans += i * N;
}
}
}
int cnt = ;
while(H > ){
ans++;
H += a[++cnt];
if(cnt == N) cnt = ;
}
Prl(ans);
return ;
}
E
F.先求一个前缀和,很显然区间和为pre[r] - pre[l - 1],先用一个n²的操作求出所有可能的和,然后用类似邻接表的方法,以区间和为key值,区间的l,r为value值存储下来.
可以将key值hash,我这里用了map<int,pair<int,int>>Q,的方式暴力存储.
对于每个key值都寻找答案,贪心的将他们所有的区间按右端点排序就可以找到这个key值下最多的区间数目.
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
LL a[maxn],pre[maxn];
map<int,vector<PII>>Q;
map<int,bool>P;
bool cmp(PII a,PII b){
return a.se < b.se;
}
int main(){
Sca(N);
for(int i = ; i <= N ; i ++){
Sca(a[i]);
pre[i] = pre[i - ] + a[i];
}
int ans = ;
for(int l = ; l <= N ; l ++){
P.clear();
for(int r = l; r <= N ; r ++){
int sum = pre[r] - pre[l - ];
if(P[sum]) continue;
P[sum] = ;
Q[sum].push_back(mp(l,r));
}
}
map<int,vector<PII>>::iterator A;
for(map<int,vector<PII>>::iterator it = Q.begin(); it != Q.end(); it++){
vector<PII>q = (*it).se;
sort(q.begin(),q.end(),cmp);
int t = ;
int cnt = ;
for(int i = ; i < q.size(); i ++){
if(q[i].fi > t){
cnt++;
t = q[i].se;
}
}
if(ans < cnt) A = it;
ans = max(ans,cnt);
}
Pri(ans);
vector<PII>q = (*A).se;
sort(q.begin(),q.end(),cmp);
int t = ;
for(int i = ; i < q.size(); i ++){
if(q[i].fi > t){
cout << q[i].fi << " " << q[i].se << endl;
t = q[i].se;
}
}
return ;
}
F
G.画画图就很显然的指导若x为公司数量ind[i] <= x的点必可以为好点,反之必为坏点.
用二分找出最小的满足坏点 <= k的公司数x,贪心的方法得到树边的染色.
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
LL a[maxn],pre[maxn];
map<int,vector<PII>>Q;
map<int,bool>P;
bool cmp(PII a,PII b){
return a.se < b.se;
}
int main(){
Sca(N);
for(int i = ; i <= N ; i ++){
Sca(a[i]);
pre[i] = pre[i - ] + a[i];
}
int ans = ;
for(int l = ; l <= N ; l ++){
P.clear();
for(int r = l; r <= N ; r ++){
int sum = pre[r] - pre[l - ];
if(P[sum]) continue;
P[sum] = ;
Q[sum].push_back(mp(l,r));
}
}
map<int,vector<PII>>::iterator A;
for(map<int,vector<PII>>::iterator it = Q.begin(); it != Q.end(); it++){
vector<PII>q = (*it).se;
sort(q.begin(),q.end(),cmp);
int t = ;
int cnt = ;
for(int i = ; i < q.size(); i ++){
if(q[i].fi > t){
cnt++;
t = q[i].se;
}
}
if(ans < cnt) A = it;
ans = max(ans,cnt);
}
Pri(ans);
vector<PII>q = (*A).se;
sort(q.begin(),q.end(),cmp);
int t = ;
for(int i = ; i < q.size(); i ++){
if(q[i].fi > t){
cout << q[i].fi << " " << q[i].se << endl;
t = q[i].se;
}
}
return ;
}
G
codeforces-1141 (div3)的更多相关文章
- Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)
Problem Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...
- codeforces #579(div3)
codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不 ...
- CodeForces 1029E div3
题目链接 第一道场上自己做出来的E题...虽然是div3,而且是原题... 当时做完ABC,D题没有思路就去怼E了,然后发现貌似原题? 事实上就是原题... 给个原题链接... [HNOI2003]消 ...
- [Codeforces #615 div3]1294E Obtain a Permutation
Before the Beginniing 本文为 Clouder 原创文章,原文链接为Click,转载时请将本段放在文章开头显眼处.如进行了二次创作,请明确标明. 由本人转载于博客园. 题意分析 C ...
- Codeforces #624 div3 C
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...
- Twist the Permutation 数列的轮换题 Codeforces 776 div3
这是一道比较经典的将数列中的数字轮换的题目,我们先看题干: 题干分析:先浅浅地分析一下题目是要我们干什么,我们会默认有一个已经升序排序地1~n的排列,然后我们会给定一个新排列是在原有排列的基础上进行o ...
- 记一次神奇的codeforces
今天有一场codeforces的div3,时间挺合适,于是就想打.结果发现rating超过1600就不能报名.虽然shzr好久不打CF了而且很菜,但是毕竟还是到了1600的,于是和ZUTTER_一起用 ...
- CodeForces Round #527 (Div3) B. Teams Forming
http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]
hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...
随机推荐
- MPP架构海量数据分析仓库——Greenplum介绍
一.Greenplum背景 时间回到2002年,互联网行业经过近10年的发展,数据量正处于快速增长期: 1.传统的主机计算模式在海量数据面前,除了造价昂贵外,在CPU计算和IO吞吐上不能满足海量数据的 ...
- SQLServer之DEFAULT约束
DEFAULT约束添加规则 1.若在表中定义了默认值约束,用户在插入新的数据行时,如果该行没有指定数据,那么系统将默认值赋给该列,如果我们不设置默认值,系统默认为NULL. 2.如果“默认值”字段中的 ...
- Redis操作集合,有序集合
Set操作,Set集合就是不允许重复的列表 sadd(name,values) 1 # name对应的集合中添加元素 scard(name) 1 获取name对应的集合中元素个数 sdiff(keys ...
- python import详解
1.import作用 引入模块 2.import的特点 一个程序中,import的模块不会重复被引用,如: # test1.py import test2 print test2.attr # tes ...
- Linux删除文件夹和修改文件名
rm [选项] 文件 -f, --force 强力删除,不要求确认 -i 每删除一个文件或进入一个子目录都要求确认 -I 在删除超过三个文件或者递归删除前要求确认 -r, -R 递归删除子目录 -d, ...
- STM32 FSMC使用笔记
最近在使用STM32的FSMC与FPGA做并行通信总线控制,做一下总结 1,利用FSMC读取写入16位数据时的封装函数如下,不这样使用的话在与FPGA进行通信的过程中可能会出现不可预知的错误. #de ...
- poj 3090 Visible Lattice Points(离线打表)
这是好久之前做过的题,算是在考察欧拉函数的定义吧. 先把欧拉函数讲好:其实欧拉函数还是有很多解读的.emmm,最基础同时最重要的算是,¢(n)表示范围(1, n-1)中与n互质的数的个数 好了,我把规 ...
- (四)Exploring Your Cluster
The REST API Now that we have our node (and cluster) up and running, the next step is to understand ...
- ansible 与 Jinja2的结合
1.文件架构 [root@master template]# tree . ├── jinj2_test.yml ├── meta ├── tasks ├── templates │ └── te ...
- 从 0 到 1 实现 React 系列 —— 1.JSX 和 Virtual DOM
看源码一个痛处是会陷进理不顺主干的困局中,本系列文章在实现一个 (x)react 的同时理顺 React 框架的主干内容(JSX/虚拟DOM/组件/生命周期/diff算法/setState/ref/. ...