codeforces-1139 (div2)
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)的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
- codeforces 235 div2 C Team
题目:http://codeforces.com/contest/401/problem/C 题意:n个0,m个1,求没有00或111的情况. 这么简单的题..... 做题的时候脑残了...,今天,贴 ...
随机推荐
- MySQL的自动提交模式
默认情况下, MySQL启用自动提交模式(变量autocommit为ON).这意味着, 只要你执行DML操作的语句,MySQL会立即隐式提交事务(Implicit Commit).这个跟SQL S ...
- webmagic 爬取网页所有文章的标题时间作者和内容
package com.ij34; import us.codecraft.webmagic.Site; import us.codecraft.webmagic.Page; import us.co ...
- Spring MVC 数据绑定 (四)
完整的项目案例: springmvc.zip 目录 实例 项目结构路径: 一.配置web.xml <?xml version="1.0" encoding="UTF ...
- c/c++ 拷贝控制 构造函数的问题
拷贝控制 构造函数的问题 问题1:下面①处的代码注释掉后,就编译不过,为什么??? 问题2:但是把②处的也注释掉后,编译就过了,为什么??? 编译错误: 001.cpp: In copy constr ...
- python3 str(字符串)
__add__函数 (在后面追加字符串) s1 ='Hello' s2 = s1.__add__(' boy!') print(s2) #输出:Hello boy! __contains__(判断是否 ...
- debian 9 开机启动
由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /etc/rc.local 文件,但是 Debian 9 默认不带 /etc/rc.local 文件,而 rc. ...
- centos7下kubernetes(16。kubernetes-滚动更新)
滚动更新:一次只更新一小部分副本,成功后,在更新更多的副本,最终完成所有副本的更新. 滚动更新的最大好处是零停机,整个更新过程始终有副本在运行,从而保证了业余的连续性 下面部署三个副本的应用,出事镜像 ...
- HTML5仿手机微信聊天界面
HTML5仿手机微信聊天界面 这篇文章主要为大家详细介绍了HTML5仿手机微信聊天界面的关键代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 给大家带来的是HTML5仿手机微信聊天界面, ...
- 理解MySQL数据库事务
1. 什么是事务处理? 事务处理是一种机制,它是用来管理必须成批执行的mysql操作.来保证数据库不完整的操作结果. 2. 为什么要使用事务处理? 在使用mysql操作数据的过程中,如果只是简单的中小 ...
- SQL Server的JOIN是支持使用小括号修改执行顺序的
假如现在我们的SQL Server数据库中有三个表:[T_A].[T_B]和[T_C],它们的建表语句如下: --建表语句[T_A] CREATE TABLE [dbo].[T_A]( [ID_A] ...