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. Zookeeper集群及配置

    特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...

  2. lianjie3

    http://7xj7xs.com1.z0.glb.clouddn.com/xiao-chengxu.mp4

  3. leetcode-mid-backtracking -22. Generate Parentheses-NO

    mycode    没有思路,大早上就有些萎靡,其实和上一个电话号码的题如出一辙啦 参考: class Solution(object): def generateParenthesis(self, ...

  4. datalist的模板里的label要绑定一个函数

    列下如何在前台绑定数据时呼叫後台方法 如下GetInfoByID是后台方法,Eval("ID").ToString()是你在前台绑定数据传入的字段名 <asp:Label I ...

  5. kaptcha Spring 整合

    转自:http://my.oschina.net/CandyDesire/blog/209364 生成验证码的方式有很多,个人认为较为灵活方便的是Kaptcha ,他是基于SimpleCaptcha的 ...

  6. Python Module_openpyxl_处理Excel表格

    目录 目录 前言 软件系统 Install openpyxl module Sample code load_workbook加载Excel文件 wbObjectget_sheet_names 获取E ...

  7. Excel公式的常见错误值及其解决方法

    Excel公式的常见错误值及其解决方法 经常用Excel的朋友可能都会遇到一些莫名奇妙的错误值信息:# N/A!.#VALUE!.#DIV/O!等等,出现这些错误的原因有很多种,如果公式不能计算正确结 ...

  8. malloc和cmalloc

    void *malloc(size_t size); 分配内存,但不会初始化,未使用内存不一定是0: void *calloc(size_t numElements,size_t sizeOfElem ...

  9. 【不错】MySQL 事务隔离级别

    一.事务描述 1.事务的四个特性 ACID 1. A:原子性 = 一个事务或者都成功.或者都失败: 2. C:一致性 = 在整个事务的生命周期里面,查询到的数据是一致的: MVCC多版本并发控制:利用 ...

  10. 使用使用dockerfile构建webapi镜像然后使用link和bridge两种方式进行桥接

    首先新增一个webapi的项目 项目核心代码 UserContext using Microsoft.EntityFrameworkCore; using System; using System.C ...