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)的更多相关文章

  1. Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)

    Problem  Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...

  2. codeforces #579(div3)

    codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不 ...

  3. CodeForces 1029E div3

    题目链接 第一道场上自己做出来的E题...虽然是div3,而且是原题... 当时做完ABC,D题没有思路就去怼E了,然后发现貌似原题? 事实上就是原题... 给个原题链接... [HNOI2003]消 ...

  4. [Codeforces #615 div3]1294E Obtain a Permutation

    Before the Beginniing 本文为 Clouder 原创文章,原文链接为Click,转载时请将本段放在文章开头显眼处.如进行了二次创作,请明确标明. 由本人转载于博客园. 题意分析 C ...

  5. Codeforces #624 div3 C

    You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...

  6. Twist the Permutation 数列的轮换题 Codeforces 776 div3

    这是一道比较经典的将数列中的数字轮换的题目,我们先看题干: 题干分析:先浅浅地分析一下题目是要我们干什么,我们会默认有一个已经升序排序地1~n的排列,然后我们会给定一个新排列是在原有排列的基础上进行o ...

  7. 记一次神奇的codeforces

    今天有一场codeforces的div3,时间挺合适,于是就想打.结果发现rating超过1600就不能报名.虽然shzr好久不打CF了而且很菜,但是毕竟还是到了1600的,于是和ZUTTER_一起用 ...

  8. 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 ...

  9. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  10. Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

    hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...

随机推荐

  1. Linux中VSFTP的配置

    配置VSFTP服务器: 1.安装VSFTP,可以参考Linux 中yum的配置来安装: yum installvsftpd.x86_64 -y 2.修改SELinux: setenforce 0 查看 ...

  2. python之生成随机密码

    https://www.cnblogs.com/evablogs/p/7096583.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #!/usr/bin/py ...

  3. git取消跟踪已版本控制的文件

    git 不再追踪文件改动 git update-index --assume-unchanged filePath git 恢复追踪文件改动 git update-index —no-assume-u ...

  4. SQLServer之PRIMARY KEY约束

    PRIMARY KEY约束添加规则 1.在表中常有一列或多列的组合,其值能唯一标识表中的每一行,这样的一列或多列成为表的主键(PrimaryKey). 2.一个表只能有一个主键,而且主键约束中的列不能 ...

  5. topjui中combobox使用

    1.创建combobox的方法 常用的一种是通过Js定义,一种是通过在input输入框中定义,还有一种通过在selete标签中定义,可以去看easyui的官方文档 http://www.jeasyui ...

  6. 【Teradata】安装SQL Assistant和Administrator 16.20(含查看.net版本)

    1.安装介质获取: 获取的路径:connections==>Gateways==>Customer Services==>TOOLS & APPLICATIONS(点击Mor ...

  7. Django 【orm】或

    方式一: q=Q() q.connection="or" q.children.append(("pk",1)) q.children.append((&quo ...

  8. linux -- 添加、修改、删除路由

    在日常的使用中,或者在服务器中,有两个网卡配置两个地址,访问不同的网络段,这种情况是非常常见的现象,但是,我们需要额外的添加路由表来决定发送的数据包经过正确的网关和interface才能正确的进行通信 ...

  9. 3.18 总结 java 基础语法

  10. pydensecrf的inference.py代码的学习

    https://github.com/lucasb-eyer/pydensecrf/blob/master/examples/inference.py 1.运行 先运行看看实现的结果: (deeple ...