A.如果第i个数字是偶数,总贡献就加上i

#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 = 1e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
char str[maxn];
int main(){
Sca(N);
scanf("%s",str + );
LL ans = ;
for(int i = ; i <= N ; i ++){
if(!((str[i] - '') & )) ans += i;
}
Prl(ans);
return ;
}

A

B.从后往前贪心,总是取当年能取的最大的。

#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 a[maxn];
int main(){
Sca(N);
for(int i = ; i <= N ; i ++){
Scl(a[i]);
}
LL now = INF;
LL ans = ;
for(int i = N; i >= && now; i --){
a[i] = min(a[i],now - );
ans += a[i];
now = a[i];
}
Prl(ans);
return ;
}

B

C.总个数是N ^ K,考虑所有不符合条件的情况,显然黑边两边的点是不可以出现在同一序列的的,所以去掉所有的黑边,并查集维护所有联通块的点,对于每个联通快,不合理的情况是size ^ K

#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;
int fa[maxn],Size[maxn];
void init(){
for(int i = ; i <= N; i ++){
fa[i] = i;
Size[i] = ;
}
}
LL cul(LL a,LL b){
LL ans = ;
while(b){
if(b & ) ans = (ans * a) % mod;
b >>= ;
a = (a * a) % mod;
}
return ans;
}
int find(int t){
if(fa[t] == t) return t;
return fa[t] = find(fa[t]);
}
void Union(int a,int b){
a = find(a); b = find(b);
if(a == b) return;
fa[a] = b;
Size[b] += Size[a];
}
int main(){
Sca2(N,K); init();
for(int i = ; i <= N - ; i ++){
int u,v,w; Sca3(u,v,w);
if(!w) Union(u,v);
}
LL sum = cul(N,K);
for(int i = ; i <= N ; i ++){
if(fa[i] == i){
sum = (sum - cul(Size[i],K) + mod) % mod;
}
}
Prl(sum);
return ;
}

C

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 = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K,Q;
PII node[maxn];
int vis[maxn];
int q[maxn];
struct Edge{
int to,next;
}edge[maxn];
int head[maxn],tot;
void init(){
for(int i = ; i < maxn; i ++) head[i] = -;
tot = ;
}
void add(int u,int v){
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
}
int linker[maxn];
int Stack[maxn],top; bool dfs(int x){
for(int i = head[x]; ~i ; i = edge[i].next){
if(vis[edge[i].to]) continue;
vis[edge[i].to] = ;
Stack[++top] = edge[i].to;
if(linker[edge[i].to] == - || dfs(linker[edge[i].to])){
linker[edge[i].to] = x;
return true;
}
}
return false;
}
bool find(int x){
for(int i = ; i <= top; i ++) vis[Stack[i]] = ;
top = ;
return dfs(x);
}
int ans[maxn];
int main(){
Sca2(N,M); init();
for(int i = ; i <= M; i ++) linker[i] = -;
for(int i = ; i <= N; i ++) node[i].fi = read();
for(int i = ; i <= N; i ++) node[i].se = read();
Sca(Q);
for(int i = ; i <= Q; i ++){
q[i] = read();
vis[q[i]] = ;
}
for(int i = ; i <= N ; i ++){
if(!vis[i]){
add(node[i].fi,node[i].se);
}
vis[i] = ;
}
int cnt = ;
while(find(cnt)) cnt++;
ans[Q] = cnt;
for(int i = Q - ;i >= ; i --){
add(node[q[i + ]].fi,node[q[i + ]].se);
while(find(cnt)) cnt++;
ans[i] = cnt;
}
for(int i = ; i <= Q; i ++) Pri(ans[i]);
return ;
}

E

codeforces-1139 (div2)的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  9. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

  10. codeforces 235 div2 C Team

    题目:http://codeforces.com/contest/401/problem/C 题意:n个0,m个1,求没有00或111的情况. 这么简单的题..... 做题的时候脑残了...,今天,贴 ...

随机推荐

  1. c/c++ 继承与多态 由子类向父类的转换规则

    问题1:子类B可以有3种方式(public, protected, private)继承父类A,用哪种方式继承,用户代码才能把子类B的对象转换成父类A的对象呢? 只用当子类B以public方式继承父类 ...

  2. 建立第一个SpringBoot小列子(碰到的错误)

    当加入@SpringBootApplication注解时,无法得到解析 错误提示:SpringBootApplication cannot be resolved to a type 错误原因是因为s ...

  3. Zabbix监控USG6300防火墙及交换机

    1.登录防火墙直接在web上面配置SNMP,只读团体名.读写团体名.Trap接收主机.安全名,点击应用完成防火墙上面的SNMP配置,如果你的命令行敲得6,可以使用命令行敲,配置效果一样,交换机没有这么 ...

  4. 安装ESXi部署OVF详细步骤

    整个安装部署过程均在个人环境进行.欧克,我们现在开始. 一.安装ESXi 1.Enter回车 2.Enter回车继续 3.F11,接受继续 4.Enter,回车继续(选择安装ESXi的设备) 5.默认 ...

  5. Extjs 解决grid分页bug问题

    //从后端获取数据加载到grid中var mainStore = new HeJsonStore({ url:'xxx', autoLoad:true, pageSize:20 }) //此方法最好放 ...

  6. 4.机器学习——统计学习三要素与最大似然估计、最大后验概率估计及L1、L2正则化

    1.前言 之前我一直对于“最大似然估计”犯迷糊,今天在看了陶轻松.忆臻.nebulaf91等人的博客以及李航老师的<统计学习方法>后,豁然开朗,于是在此记下一些心得体会. “最大似然估计” ...

  7. China Tightens Recycling Import Rules

    China Tightens Recycling Import Rules We have all seen the pictures of cities in China with air poll ...

  8. springMVC DispatcherServlet类关系图

  9. BZOJ 3684 大朋友和多叉树

    BZOJ 3684 大朋友和多叉树 Description 我们的大朋友很喜欢计算机科学,而且尤其喜欢多叉树.对于一棵带有正整数点权的有根多叉树,如果它满足这样的性质,我们的大朋友就会将其称作神犇的: ...

  10. Windows服务器环境下jenkins下载和安装

    1.下载jenkins 在windows系统上搭建jenkins持续集成有两种方法:1.war文件,可以用tomcat或者java命令直接运行2.msi安装,作为系统服务后台运行 下载地址 https ...