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 ...
随机推荐
- flask包request获取参数
原博文:https://www.cnblogs.com/wangjikun/p/6935592.html request.method #获取请求方法request.form #获取post请求所有参 ...
- JDBC操作数据库的基本操作
JDBC操作数据库的基本步骤: 1)加载(注册)数据库驱动(到JVM). 2)建立(获取)数据库连接. 3)创建(获取)数据库操作对象. 4)定义操作的SQL语句. 5)执行数据库操作. 6)获取并操 ...
- 【HR系列】SAP HR PA信息类型的创建与增强
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HR系列]SAP HR PA信息类型的创建与增 ...
- python_面试题_DB相关问题
1.mysql部分 问题 问题1:mysql的存储引擎 问题2:mysql的索引机制 问题3:mysql的事务以及事务隔离级别 问题4:mvcc/GAP lock是做什么的 问题5:mysql的悲观锁 ...
- mariadb数据库基础
1.数据库介绍 简单的说,数据库就是一个存放数据的仓库,这个仓库是按照一定的数据结构(数据结构是指数据的组织形式或数据之间的联系)来组织,存储的,我们可以通过数据库提供的多种方法来管理数据库里的数据 ...
- magento form.html不显示 window 和 Linux下的区别
window 无大小写区别,所以可以显示表框 Linux 大小写敏感,显示不了 \app\code\community\Company\BabyPay\Model\Payment.php 里定义了fo ...
- C语言作业11
问题 答案 这个作业属于那个课程 C语言程序设计 这个作业要求在哪里 https://www.cnblogs.com/galen123/p/11996995.html 我在这个课程的目标是 在学好C语 ...
- Hadoop+HBase分布式部署
test 版本选择
- 小记-----如何把本地jar包加载到maven库中
1.从maven中央库下载下jar包
- 第一次参赛经历:ecfinal总结
刚接到要去参加ec的消息时,还是非常激动的,毕竟第一次参赛就参加如此高水平的编程竞赛(更高水平的比赛就是wf). 教练临时组队,把三个从没在一起打过比赛的三个人组成一队,当时有点担心默契和配合上的问题 ...