Codeforces 911 三循环数覆盖问题 逆序对数结论题 栈操作模拟
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
int num[];
int main()
{
vector<int> ans;
int minn=2e9;
int n;
cin >> n;
for(int i=;i<=n;i++)
{
scanf("%d",&num[i]);
minn=min(minn,num[i]);
}
for(int i=;i<=n;i++)
{
if(num[i]==minn)
{
ans.push_back(i);
}
}
int anser=1e9;
for(int i=;i<ans.size()-;i++)
{
anser=min(anser,ans[i+]-ans[i]);
}
cout<<anser<<endl;
}
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 num[];
int main()
{
int n,a,b;
cin >> n >> a >> b;
for(int i=min(a,b);;i--)
{
if(a/i+b/i>=n)
{
cout<<i<<endl;
return ;
}
}
}
C
我们知道当三个里面的最小值都大于三的时候肯定不行 当有一个为1的时候肯定行 当2的个数不小于两个的时候肯定行 三个全为3也肯定行
剩下的就是 244这种情况
#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 num[];
int main()
{
int a, b, c;
cin >> a >> b >> c;
num[a]++, num[b]++, num[c]++;
if (min(min(a, b), c) == )
{
cout << "YES" << endl;
return ;
}
if (num[] == && num[] == )
{
cout << "YES" << endl;
return ;
}
if (num[] >= || num[] == )
{
cout << "YES" << endl;
return ;
}
cout << "NO" << endl;
}
D
假设一个区间内的逆序对数为N 区间为L-R 则不为逆序对的数翻转之后会变成逆序对 本为逆序对的翻转之后变成正常 而1-L -1 R+1-N的逆序对并不会受到影响
所以最终的答案就是SUM-N+(R-L+1)*(R-L)/2-N=SUM+(R-L+1)*(R-L)/2-2*N 因为2*N肯定是偶数 减去不影响答案的奇偶性 所以只要判断(R-L+1)*(R-L)/2是奇数还是偶数就行
#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 num[];
int c[][];
int dp[][];
ll sum = ;
int main()
{
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
scanf("%d", &num[i]);
}
for (int i = ; i <= n; i++)
{
for (int j = num[i] - ; j >= ; j--)
{
c[i][j]++;
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
c[j][i] += c[j - ][i];
}
}
for (int i = ; i <= n; i++)
{
sum += c[i - ][num[i]];
}
int flag;
if(sum%)
flag=;
else
flag=;
int q;
cin >> q;
while (q--)
{
int l,r;
cin >> l >> r;
if(((r-l+)*(r-l)/)%)
flag^=;
if(flag)
cout<<"odd"<<endl;
else
cout<<"even"<<endl;
}
}
E
#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 anser[];
int num[];
int visit[];
stack<int> sta;
vector<int> ans;
int main()
{
int cur = ;
int n, m;
cin >> n >> m;
for (int i = ; i <= m; i++)
{
cin >> num[i];
anser[i] = num[i];
visit[num[i]] = ;
sta.push(num[i]);
while (sta.size() && cur == sta.top())
{
sta.pop();
cur++;
}
}
int now;
while (cur <= n || (!sta.empty() && sta.top() > cur))
{
if (sta.size())
{
now = sta.top();
}
else
{
now = n + ;
}
for (int i = now - ; i >= cur; i--)
{
if (visit[i])
{
cout << - << endl;
return ;
}
else
{
anser[++m] = i;
sta.push(i);
visit[i] = ;
}
}
while (sta.size() && cur == sta.top())
{
sta.pop();
cur++;
}
}
if (sta.size())
{
cout << - << endl;
return ;
}
for (int i = ; i <= n; i++)
{
cout << anser[i] << " ";
}
cout << endl;
}
Codeforces 911 三循环数覆盖问题 逆序对数结论题 栈操作模拟的更多相关文章
- Codeforces 351B Jeff and Furik:概率 + 逆序对【结论题 or dp】
题目链接:http://codeforces.com/problemset/problem/351/B 题意: 给你一个1到n的排列a[i]. Jeff和Furik轮流操作,Jeff先手. Jeff每 ...
- 归并排序(归并排序求逆序对数)--16--归并排序--Leetcode面试题51.数组中的逆序对
面试题51. 数组中的逆序对 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数. 示例 1: 输入: [7,5,6,4] 输出 ...
- hdu 4911 求逆序对数+树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=4911 给定一个序列,有k次机会交换相邻两个位置的数,问说最后序列的逆序对数最少为多少. 实际上每交换一次能且只能 ...
- bzoj 3744 Gty的妹子序列 区间逆序对数(在线) 分块
题目链接 题意 给定\(n\)个数,\(q\)个询问,每次询问\([l,r]\)区间内的逆序对数. 强制在线. 思路 参考:http://www.cnblogs.com/candy99/p/65795 ...
- 求逆序对数总结 & 归并排序
用归并排序方式 最原始的方法的复杂度是O(n^2). 使用归并排序的方式,可以把复杂度降低到O(nlgn). 设A[1..n]是一个包含N个非负整数的数组.如果在i〈 j的情况下,有A〉A[j],则( ...
- 【Codeforces】CF 911 D. Inversion Counting(逆序对+思维)
题目 传送门:QWQ 分析 思维要求比较高. 首先我们要把原图的逆序对q算出来. 这个树状数组或归并排序都ok(树状数组不用离散化好评) 那么翻转$[l,r]$中的数怎么做呢? 暴力过不了,我试过了. ...
- CodeForces - 987E Petr and Permutations (思维+逆序对)
题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归 ...
- Codeforces 987 K预处理BFS 3n,7n+1随机结论题/不动点逆序对 X&Y=0连边DFS求连通块数目
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...
- 归并求逆序数(逆序对数) && 线段树求逆序数
Brainman Time Limit: 1000 MS Memory Limit: 30000 KB 64-bit integer IO format: %I64d , %I64u Java c ...
随机推荐
- Jmeter(十)负载生成器
使用LoadRunner时, 产生负载会用到利器Load Generator, 来远程控制负载机进行测试. Jmeter也不例外, 由此可见, 工具与工具之间, 达到的目的必是相同, 只是手段不一样罢 ...
- 【转】Eureka集群
Eureka作为SpringCloud的服务发现与注册中心,在整个的微服务体系中,处于核心位置.单一的eureka服务,显然不能满足高可用的实际生产环境,这就要求我们配置一个能够应对各种突发情况,具有 ...
- 因修改/etc/ssh权限导致的ssh不能连接异常解决方法
因修改/etc/ssh权限导致的ssh不能连接异常解决方法 现象: $ssh XXX@192.168.5.21 出现以下问题 Read from socket failed: Connection r ...
- sql server 字符串拆分
最近项目调取存储的时候直接传入string 作为in的查询范围,结果报错了,深思之后才发现,数据库对于传进来的String,并不是我们想的直接可以作为参数,而是作为一个整体,而in是需要一个类似arr ...
- 慕课网_反射——Java高级开发必须懂的
第1章 Class类的使用 1-1 Class类的使用 (15:18) 第2章 动态加载类 2-1 Java 动态加载类 (13:19) 第3章 获取方法信息 3-1 Java 获取方法信息 (17: ...
- How do I add a Foreign Key Field to a ModelForm in Django?
What I would like to do is to display a single form that lets the user: Enter a document title (from ...
- unity 角色换装
unity角色换装的关键是更改角色部位上的物体的SkinnedMeshRenderer组件的属性: 更改mesh:mesh决定了部位的物体的外形,是主要的数据. 刷新骨骼:同一个部位下,不同的mesh ...
- LeetCode.1033-移动石头直到连续(Moving Stones Until Consecutive)
这是小川的第386次更新,第414篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第247题(顺位题号是1033).在a,b和c位置的数字线上有三块石头.每次,你在一个终点 ...
- mysql8无法用navicat连接(mysql8加密方式的坑)
关键词:mysql8无法用navicat连接,navicat无法连接mysql8,mysql8,mysql8的加密方式 [1]mysql8 的坑 密码加密规则 在MySQL 8.0.以上版本中,cac ...
- Virtual DOM和snabbdom.js
Virtual DOM和snabbdom.js:https://www.jianshu.com/p/1f1ef915e83e