Codeforces 962 /2错误 相间位置排列 堆模拟 X轴距离最小值 前向星点双连通分量求只存在在一个简单环中的边
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轴距离最小值 前向星点双连通分量求只存在在一个简单环中的边的更多相关文章
- jquery.validate,错误信息位置
好长时间没有用jquery.validate.js这个插件了,忘得差不多了.唉,好东西还是要经常拿出来看看的,今天用jquery.validate来做一个小东西,遇到一个问题,就是错误提示信息的位置问 ...
- justify-content 定义子元素在父元素水平位置排列的顺序
justify-content 定义子元素在父元素水平位置排列的顺序,需要和display:flex使用才会生效. 有五个属性: 1.flex-start(默认值) 左对齐 2.flex-end 右 ...
- [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)
[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...
- [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)
[Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...
- codeforces 962F.simple cycle(tarjan/点双连通分量)
题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任 ...
- C#获取网页中某个元素的位置,并模拟点击
我们在开发中,往往要得到网页中某个元素的位置,并且点击它.要模拟一次鼠标点击并不难,只要调用一个API就行了,关键就是怎么样得到这个元素的位置,还有判断是否要滚动滚动条,要滚动多少行能让元素显示出来. ...
- codeforces 373 A - Efim and Strange Grade(算数模拟)
codeforces 373 A - Efim and Strange Grade(算数模拟) 原题:Efim and Strange Grade 题意:给出一个n位的实型数,你可以选择t次在任意位进 ...
- [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)
[Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...
- Codeforces 521E - Cycling City(点双连通分量+分类讨论)
Codeforces 题面传送门 & 洛谷题面传送门 大家都是暴力找生成树然后跳路径,代码不到 50 行(暴论)的一说--好,那本蒟蒻决定提供一种代码 150 行,但复杂度也是线性的分类讨论做 ...
随机推荐
- python常用笔记
A trick when you want to flatten a matrix X of shape (a,b,c,d) to a matrix X_flatten of shape (b*c*d ...
- git && github 相关
权限问题(error: The requested URL returned error: 403 Forbidden while accessing):1. 将自己机器的ssh public key ...
- 事务的ACID属性
事务,一个操作序列,这些操作要么都执行,要么都不执行,是一个不可分割的整体. ACID为事务的四大属性 原子性(Atomic):指整个数据库事务是不可分割的工作单位.只有使据库中所有的操作执行成功,才 ...
- VS2010远程调试C#程序
场景: 客户的计算机运行程序出现异常,由于办公场所不在一起,无法直接在客户的机器上调试.此时希望可以直接在开发人员的计算机(本地机器)上远程调试客户机上的软件. 假设: 本地机器的系统账户为 GIS, ...
- 你知道 Git 是如何做版本控制的吗?(转)
总结:阅读这篇文章需要20分钟 本文是转载自 滴滴WebApp架构组 的一篇文章,文章讲解了神秘的.git目录下的一些文件,最终阐述了git是如何存储数据,及git分支的相关内容. git如何存储数据 ...
- Jmeter之查看结果树
在编写接口测试脚本的时候,需要进行调试和查看结果是否正常的情况,这个时候可以使用查看结果树组件进行. 查看结果树中展示了每一个取样器的结果.请求信息和响应信息,可以查看这些内容去分析脚本是否存在问题. ...
- linux系统查找大文件脚本
每次遇到服务器磁盘满,都会很苦恼,但有了下面两种方法就可以轻松找到机器中的大文件了, 第一种:du -sh du -sh 当前目录下个文件或目录的大小: du -sh * 显示前10个占用空间最大的文 ...
- Java与C#不同
1.C#方法定义可以有默认参数,而Java则不支持该方式. C#方法定义 public void ShowMessage(string text,string orderId="" ...
- Linux 自学shell
1.多个命令用";"分号分割 还可以使用alias 给命令取别名 alias foo='cd /usr ; ls; cd -'2.使用管道线"|" 一个命令的标 ...
- 基于opencv简单的图片截取
import xml.etree.ElementTree as ET import os, cv2 from tqdm import tqdm annota_dir = 'C:\\Users\\Adm ...