A

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { , }, { , -}, { -, }};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll pre[];
int main()
{
//freopen("out.txt","w",stdout);
int n;
cin >> n;
ll sum = ;
ll now;
for (int i = ; i <= n; i++)
{
cin >> now;
pre[i] = pre[i - ] + now;
sum += now;
}
for (int i = ; i <= n; i++)
{
if (pre[i]*>= sum)
{
cout << i << endl;
return ;
}
}
}

B

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { , }, { , -}, { -, }};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int kuai[];
int pop = ;
int main()
{
//freopen("out.txt","w",stdout);
int n, a, b;
cin >> n >> a >> b;
string s;
cin >> s;
int len = s.size();
int cur = ;
for (int i = ; i <= n; i++)
{
if (i == n || s[i] == '*')
{
kuai[++pop] = cur;
cur = ;
continue;
}
if (s[i] == '.')
{
cur++;
}
}
int anser = ;
int jian;
for (int i = ; i <= pop; i++)
{
if (kuai[i] == )
{
continue;
}
//cout << kuai[i] << " ";
if (kuai[i] % == )
{
anser += min(a, kuai[i] / ) + min(b, kuai[i] / );
a -= min(a, kuai[i] / );
b -= min(b, kuai[i] / );
}
else
{
anser += min(a, kuai[i] / ) + min(b, kuai[i] / );
a -= min(a, kuai[i] / );
b -= min(b, kuai[i] / );
if (a >= b && a > )
{
anser++;
a--;
continue;
}
if (b >= a && b > )
{
anser++;
b--;
continue;
}
}
}
cout << anser << endl;
}

C

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { , }, { , -}, { -, }};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll n;
ll lenn = ;
ll len = ;
ll sqr[];
int pop = ;
ll anser = ;
int aim[];
int num[];
int dfs(int x, int str)
{
if (x == )
{
return ;
}
if (str == && x != )
{
return ;
}
if (x % == str % )
{
return dfs(x / , str / );
}
else
{
return dfs(x, str / );
}
}
int main()
{
//freopen("out.txt","w",stdout);
cin >> n;
for (ll i = ; i <= ; i++)
{
if (1LL * i * i > )
{
break;
}
else
{
sqr[i] = 1LL * i * i;
pop++;
}
}
ll cur = n;
ll now = ;
int flag;
while (cur > )
{
num[cur % ]++;
cur /= ;
lenn++;
}
for (int i = ; i <= pop; i++)
{
mem(aim, );
cur = sqr[i];
flag = dfs(cur, n);
if (flag)
{
len = ;
cur = sqr[i];
while (cur > )
{
cur /= ;
len++;
}
anser = min(lenn - len,anser);
}
}
if (anser == )
{
cout << - << endl;
}
else
{
cout << anser << endl;
}
}

D

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { , }, { , -}, { -, }};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll num[];
int visit[];
int anser = ;
pair<ll, ll> cur, cnt, now;
priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > que;
int main()
{
//freopen("out.txt","w",stdout);
ll n;
cin >> n;
for (int i = ; i <= n; i++)
{
scanf("%lld", &num[i]);
}
for (int i = ; i <= n; i++)
{
cur.first = num[i], cur.second = i;
que.push(cur);
}
while (!que.empty())
{
cur = que.top();
que.pop();
if (que.top().first > cur.first || !que.size())
{
visit[cur.second] = ;
num[cur.second] = cur.first;
continue;
}
cnt = que.top();
que.pop();
num[cnt.second] = cur.first + cnt.first;
now.first = cur.first + cnt.first, now.second = cnt.second;
que.push(now);
}
for (int i = ; i <= n; i++)
{
if (visit[i])
{
anser++;
}
}
cout << anser << endl;
for (int i = ; i <= n; i++)
{
if (visit[i])
{
cout << num[i] << " ";
}
}
cout << endl;
}

E

#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<cstdlib>
#include<ctime>
#include<stack>
#include<bitset>
using namespace std;
#define mes(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(i = a; i <= b; i++)
#define dec(i,a,b) for(i = b; i >= a; i--)
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,L,mid
#define rson rs,mid+1,R
typedef double db;
typedef long long int ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const ll inf = 1e15;
const int mx = 2e5+;
const int x_move[] = {,-,,,,,-,-};
const int y_move[] = {,,,-,,-,,-};
int main(){
int t,q,ca = ;
int n;
ll pa,pb,pc;
ll ans = ;
pa = pb = pc = inf;
ll pra = ,prb = ;
scanf("%d",&n);
for(int i = ; i < n; i++){
ll v;
char str[];
scanf("%I64d%s",&v,str);
if(str[]=='R'){
if(pa!=inf){
pra = max(pra,v-pa);
ans += v-pa;
}
pa = v;
}
else if(str[]=='B'){
if(pb!=inf){
prb = max(prb,v-pb);
ans += v-pb;
}
pb = v;
}
else{
if(pb!=inf){
prb = max(prb,v-pb);
ans += v-pb;
}
if(pa!=inf){
pra = max(pra,v-pa);
ans += v-pa;
}
if(pc!=inf)
ans = min(ans,ans+v-pc-pra-prb);
pa = pb = pc = v;
pra = prb = ;
}
}
printf("%I64d\n",ans);
return ;
}

F

因为边连通无法处理一个点同时在两个环中的情况 所以用点连通缩点 最后判一下点连通分量中是否是点的数量等于边的数量(简单环性质)

如果是的话 当前点连通分量中的边是答案的一部分

/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + ;
const int gakki = + + + + 1e9;
const int MAXN = 2e5 + ;
const int MAXM = 2e5 + ;
int to[MAXM << ], nxt[MAXM << ], Head[MAXN], tot = ;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}
int n, m;
int dfn[MAXN], low[MAXN], dfs_clock = ;
int BCCcnt = , blong[MAXN], inque[MAXM << ];
int st[MAXN], l = , ans[MAXN], ansnum = ;
bool vis[MAXM << ];
void tarjanBCC(int x, int fa)
{
dfn[x] = low[x] = ++dfs_clock;
for (int i = Head[x]; i; i = nxt[i])
{
int v = to[i];
if (v == fa || vis[i])
{
continue;
}
vis[i] = vis[i ^ ] = ;
st[l++] = i;
if (!dfn[v])
{
tarjanBCC(v, x);
low[x] = min(low[v], low[x]);
if (dfn[x] <= low[v])
{
int now, vnumber = , enumber = ;
BCCcnt++;
while()
{
now = st[--l];
if (blong[to[now]] != BCCcnt)
{
blong[to[now]] = BCCcnt, ++vnumber;
}
if (blong[to[now ^ ]] != BCCcnt)
{
blong[to[now ^ ]] = BCCcnt, ++vnumber;
}
inque[++enumber] = now;
if(now==i)
break;
}
if (vnumber == enumber)
{
for (int i = ; i <= enumber; i++)
{
ans[++ansnum] = inque[i] / ;
}
}
}
}
else
{
low[x] = min(low[x], dfn[v]);
}
}
}
int main()
{
ios_base::sync_with_stdio();
cin.tie();
cin >> n >> m;
int u, v;
for (int i = ; i <= m; i++)
{
cin >> u >> v;
addedge(u, v), addedge(v, u);
}
for (int i = ; i <= n; i++)
{
if (!dfn[i])
{
tarjanBCC(i, -);
}
}
sort(ans + , ans + + ansnum);
cout << ansnum << endl;
for (int i = ; i <= ansnum; i++)
{
cout << ans[i] << " ";
}
return ;
}

Codeforces 962 /2错误 相间位置排列 堆模拟 X轴距离最小值 前向星点双连通分量求只存在在一个简单环中的边的更多相关文章

  1. jquery.validate,错误信息位置

    好长时间没有用jquery.validate.js这个插件了,忘得差不多了.唉,好东西还是要经常拿出来看看的,今天用jquery.validate来做一个小东西,遇到一个问题,就是错误提示信息的位置问 ...

  2. justify-content 定义子元素在父元素水平位置排列的顺序

    justify-content 定义子元素在父元素水平位置排列的顺序,需要和display:flex使用才会生效. 有五个属性: 1.flex-start(默认值)  左对齐 2.flex-end 右 ...

  3. [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)

    [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...

  4. [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)

    [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...

  5. codeforces 962F.simple cycle(tarjan/点双连通分量)

    题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任 ...

  6. C#获取网页中某个元素的位置,并模拟点击

    我们在开发中,往往要得到网页中某个元素的位置,并且点击它.要模拟一次鼠标点击并不难,只要调用一个API就行了,关键就是怎么样得到这个元素的位置,还有判断是否要滚动滚动条,要滚动多少行能让元素显示出来. ...

  7. codeforces 373 A - Efim and Strange Grade(算数模拟)

    codeforces 373 A - Efim and Strange Grade(算数模拟) 原题:Efim and Strange Grade 题意:给出一个n位的实型数,你可以选择t次在任意位进 ...

  8. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

  9. Codeforces 521E - Cycling City(点双连通分量+分类讨论)

    Codeforces 题面传送门 & 洛谷题面传送门 大家都是暴力找生成树然后跳路径,代码不到 50 行(暴论)的一说--好,那本蒟蒻决定提供一种代码 150 行,但复杂度也是线性的分类讨论做 ...

随机推荐

  1. Spring下面的@Transactional注解的讲解

    摘自: https://www.cnblogs.com/xiohao/p/4808088.html Spring下面的@Transactional注解标志的讲解 最近在开发中对Spring中的事务标记 ...

  2. leetcode 134 加油站问题

    leetcode 134 解析 在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升. 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 co ...

  3. seleniumIDE回放找不到页面元素

    seleniumIDE回放找不到页面元素 如下所示,自动回放就报错,手动执行就不报错.

  4. 【转载】inno setup 水波纹效果,检测安装vcredist_x86.exe等

    以下inno setup脚本,实现了:1.水波纹效果 2.安装时检测是否安装其他版本,并在欢迎页面添加文字提示 4.检测安装vcredist_x86.exe  3.卸载时添加提示 ; 脚本由 Inno ...

  5. c++ 调用 sqlite

    #include <iostream> #include "sqlite3.h" using namespace std; void dbTest() { #pragm ...

  6. HTML5——web存储 Web SQL 数据库 应用程序缓存 Web Workers 服务器发送事件 WebSocket

    web存储 比cookie更好的本地存储方式 localStorage - 用于长久保存整个网站的数据,保存的数据没有过期时间,直到手动去除. sessionStorage - 用于临时保存同一窗口( ...

  7. Java之类的继承

    说起来Java的类,不得不说以下几个方面:继承.转型.重写.多态和接口. 今天来说一说继承,转型和重写几个方面: 继承(extends)即子类继承父类,就好比玻璃杯.保温杯等子类继承了杯子这个父类,子 ...

  8. 使用Dockerfile制作镜像

    组成部分 基础镜像信息       FROM 维护者信息    MAINTAINER.LABEL 镜像操作指令       RUN.COPY.ADD.EXPOSE.WORKDIR.ONBUILD.US ...

  9. IIS7下配置web.config隐藏index.php

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.we ...

  10. 2019上海网络赛B题(差分 + 离散化 or 差分 + 思维)

    这题.....队里都没怎么训练差分,导致败北...写了一堆线段树嘤嘤嘤,到最后也是超时,比赛结束后看到了差分的思想于是就去学了一手. 其实了解差分思想的一眼就能看出来是差分了.但是如果对n差分的话很明 ...