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了,感觉应该 ...
随机推荐
- .net向文件写入字符串流内存溢出的问题
字符串过大导致抛出异常: exceptopm of type 'system.outOfmemoryexception' was thrown 解决方法:逐块写入可以避免这个问题
- 含有package关键字的java文件在命令行运行报错
程序中含有package关键字,使用命令行运行程序时出现"找不到或无法加载主类",而使用Eclipse软件可以正常运行程序的可能解决办法. 在包下的类,在Java源文件的地方编译后 ...
- LeetCode算法题-Baseball Game(Java实现)
这是悦乐书的第288次更新,第305篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第156题(顺位题号是682).你现在是棒球比赛点记录器.给定一个字符串列表,每个字符串 ...
- LeetCode算法题-Set Mismatch(Java实现)
这是悦乐书的第279次更新,第295篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第147题(顺位题号是645).集合S最初包含从1到n的数字. 但不幸的是,由于数据错误 ...
- Log4j配置文件详解及实例
1 ) . 配置根 Logger ,其语法为: log4j.rootLogger = [ level ] , appenderName, appenderName, … 其中, level 是日 ...
- 【Python 01】Python可以做什么
Python学习未来方向: 1.数据分析 2.自然语言处理 3.社交网络分析 4.人工智能 5.深度学习 6.计算机视觉 7.网络爬虫 8.量化交易
- day22-多并发编程基础(三)
今天学习了并发编程中的最后一部分,协程,也是python中区别于java,c等语言中很大不同的一部分 1.协程产生的背景 2.协程的概念 3.yield模拟协程 4.协程中主要的俩个模块 5.协程的应 ...
- rtsp 流媒体服务器,播放器
https://github.com/EasyDSS/EasyPlayer-RTSP-Android EasyPlayer EasyPlayer RTSP Android 播放器是由紫鲸团队开发和维护 ...
- matlab读取cvs文件的几种方法
matlab读取CVS文件的几种方法: 1,实用csvread()函数 csvread()函数有三种使用方法: 1.M = csvread('filename')2.M = csvread('fi ...
- Lepus搭建企业级数据库慢查询分析平台
前言 Lepus的慢查询分析平台是独立于监控系统的模块,该功能需要使用percona-toolkit工具来采集和记录慢查询日志,并且需要部署一个我们提供的shell脚本来进行数据采集.该脚本会自动开启 ...