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. ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

    今天在MySQL 5.6版本的数据库中修改InnoDB表字段长度时遇到了"ERROR 1071 (42000): Specified key was too long; max key le ...

  2. SQL 日期时间比较

    原先的判断是 ae.首次受理时刻 >= '2015/12/1 0:00:00'  AND ae.首次受理时刻 <= '2015/12/25 0:00:00' ,改为如下和时间变量比较 效率 ...

  3. 解决vs启动出现“cannot find one or more components .Please reinstall the application”

    参考下文: https://blog.csdn.net/novice_growth/article/details/71627395

  4. MFC打印

    映射模式是MFC甚至SDK界面编程第1个难点.打印则是第2个难点.这2个都是历史遗留的设计缺陷.这些缺陷还不至于到bug程度,但却很难用,不易理解. MFC提供2个类来实现打印(预览),具体有CPri ...

  5. ASP.NET MVC5学习系列——身份验证、授权

    一.什么是身份验证和授权 人们有时对用户身份验证和用户授权之间的区别感到疑惑.用户身份验证是指通过某种形式的登录机制(包括用户名/密码.OpenID.OAuth等说明身份的项)来核实用户的身份.授权验 ...

  6. .net 添加api不能访问的问题

    在一个.netmvc项目中,本身没有提供api后来想添加api就会出现问题.会发生添加的apicontrol不能访问的情况.这种情况一般是因为,global文件中,application_start( ...

  7. 设计模式之Template Method模式

    作用:将具体的处理交给子类 什么是Template Method模式? Template Method模式是指带有模板功能的模式,组成模板的方法被定义在父类中,且这些方法为抽象方法.子类去实现父类中的 ...

  8. 19 python初学(os 模块,sys 模块,hashlib 模块)

    os 模块: # _author: lily # _date: 2019/1/13 import os print(os.getcwd()) # 得到当前的工作目录 # print(os.chdir( ...

  9. android H5支付 网络环境未能通过安全验证,请稍后再试

    android做混合开发微信H5支付时碰到的一个问题. 解决办法:把所使用的WebView中重新如下方法即可 webView.setWebViewClient(new WebViewClient() ...

  10. 《App架构实践指南》

    推荐书籍 <App 架构实践指南>