Codeforces 939 时区模拟 三分
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 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int num[];
int main()
{
int n;
cin >> n;
for(int i=; i<=n; i++)
{
cin >> num[i];
}
int flag=;
for(int i=; i<=n; i++)
{
int time=;
int aim=num[i];
while(time--)
{
aim=num[aim];
}
if(aim==i)
{
cout<<"YES"<<endl;
return ;
}
}
cout<<"NO"<<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 1e9
//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 Mod = ;
int main()
{
ll aim=,anser;
ll remain=1e18+;
ll n,k;
cin >> n >> k;
for(int i=;i<=k;i++)
{
ll now;
cin >> now;
if((n-1LL*n/now*now)<remain)
{
aim=i;
anser=n/now;
remain=n-1LL*n/now*now;
}
}
cout<<aim<<" "<<anser<<endl;
return ;
}
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 1e9
//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 Mod = ;
ll num[];
ll pre[];
ll ans;
ll now;
int main()
{
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
scanf("%lld", num + i);
num[i + n] = num[i];
}
ll L, R;
cin >> L >> R;
for (int i = L; i < R; i++)
{
ans += num[i];
}
now = ans;
int aim = ;
for (int i = ; i <= n; i++)
{
now = now - num[ + n + R - i] + num[ + n + L - i];
if (now > ans)
{
aim = i;
ans = now;
}
}
cout << aim << endl;
return ;
}
D
转化题意为求联通块 可以并查集也可以直接DFS 答案为每个联通块内点数-1的和
#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 1e9
//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 Mod = ;
string a, b;
int gra[][];
int visit[];
int belong[];
int block[];
void dfs(int x, int aim)
{
visit[x] = ;
belong[x] = aim;
for (int i = ; i <= ; i++)
{
if (gra[x][i] && !visit[i])
{
block[aim]++;
dfs(i, aim);
}
}
}
int main()
{
for (int i = ; i <= ; i++)
{
belong[i] = ;
}
for (int i = ; i <= ; i++)
{
block[i] = visit[i] = ;
}
int n;
cin >> n;
cin >> a >> b;
for (int i = ; i < n; i++)
{
if (a[i] != b[i])
{
visit[a[i] - 'a'] = visit[b[i] - 'a'] = ;
gra[a[i] - 'a'][b[i] - 'a'] = gra[b[i] - 'a'][a[i] - 'a'] = ;
}
}
for (int i = ; i <= ; i++)
{
if (visit[i])
{
continue;
}
dfs(i, i);
}
int ans = ;
for (int i = ; i <= ; i++)
{
if (block[i] > )
{
ans += block[i] - ;
}
}
cout << ans << endl;
for (int i = ; i <= ; i++)
{
if (belong[i] != && i != belong[i])
{
cout << (char)('a' + i) << " " << (char)('a' + belong[i]) << endl;
}
}
return ;
}
E
裸的一个三分 分析题意可以得到 答案为 ans=maxn-(maxn+pre[k])/(k+1) 为凸函数
也可以记录前一个query的答案然后向后推进
因为随着最大值越来越大maxn-(maxn+pre[k])/(k+1)的值会越来越大 而你要求加进去的前缀里的数只要小于(maxn+pre[k])/(k+1)这个平均值就可以了
#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 1e9
//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 Mod = ;
ll num[];
ll pre[];
int pop;
int l, r;
double f(int x)
{
return ((double)(num[pop]) - (((double)(num[pop]) + (double)(pre[x])) / (double)(x + )));
}
double SF()
{
while (l < r - )
{
int mid = (l + r) >> ;
int mmid = (mid + r) >> ;
if (f(mid) > f(mmid))
{
r = mmid;
}
else
{
l = mid;
}
}
return max(f(l + ), max(f(l), f(r)));
}
int main()
{
int q;
int ch;
ll number;
cin >> q;
for (int i = ; i <= q; i++)
{
scanf("%d", &ch);
if (ch == )
{
scanf("%lld", &number);
num[++pop] = number;
pre[pop] = pre[pop - ] + number;
}
else
{
if (pop == )
{
cout << "0.00000000" << endl;
continue;
}
if (pop == )
{
printf("%.9f\n", (double)(num[]) - ((double)num[] + num[]) / 2.0);
continue;
}
l = , r = pop - ;
printf("%.9f\n", SF());
}
}
return ;
}
Codeforces 939 时区模拟 三分的更多相关文章
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces 679B. Barnicle 模拟
B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...
- CodeForces 382C【模拟】
活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...
- codeforces 719C (复杂模拟-四舍五入-贪心)
题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑...
- CodeForces 705C Thor (模拟+STL)
题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...
- codeforces 645C . Enduring Exodus 三分
题目链接 我们将所有为0的位置的下标存起来. 然后我们枚举左端点i, 那么i+k就是右端点. 然后我们三分John的位置, 找到下标为i时的最小值. 复杂度 $ O(nlogn) $ #include ...
随机推荐
- pwd命令学习
pwd命令学习 1.学习pwd命令 pwd命令功能为输出当前所在工作目录的绝对路径名称. 绝对路径和相对路径: 绝对路径:从根目录开始直到文件位置 相对路径:相对于程序当前所在目录到文件位置 例:程序 ...
- hook C++
Intercepting Calls to COM Interfaces(hook com接口) 通过COM组件IFileOperation越权复制文件 代码注入之远程线程篇 使用VC++通过远程进程 ...
- Git - 对一组仓库进行配置
对一组仓库使用一套配置,另一组仓库使用另一套配置的需求也是有的,比如公司仓库的配置和我个人项目的仓库配置并不完全相同,每次都修改单个仓库的配置太麻烦并且可能会粗心忘改了以错误的配置进行提交,如何对一个 ...
- Java -- 泛型父类中获取子类的泛型T
原文:https://blog.csdn.net/u014723529/article/details/70574026 /** * 获取实体类型名称 * 子类可覆盖此方法,返回:泛型T的类名.cla ...
- 前端必须掌握的 docker 技能(3)
概述 作为一个前端,我觉得必须要学会使用 docker 干下面几件事: 部署前端应用 部署 nginx 给部署的 nginx 加上 https 使用 docker compose 进行部署 给 ngi ...
- Object.freeze与 Object.seal的区别
Object.freeze()冻结一个对象.不能添加新的属性,不能删除已有属性,不能修改该对象已有属性的可枚举性.可配置性.可写性,以及不能修改已有属性的值.冻结一个对象后该对象的原型也不能被修改. ...
- 【工具安装】BurpSuite 安装教程
日期:2019-07-14 17:23:53 介绍:安装 JDK,配置 JDK 的环境变量.安装 BurpSuite,抓包 0x01. 安装 JDK 安装 JDK BurpSuite 需要 JAVA ...
- 【SSH】---【Struts2、Hibernate5、Spring4】【散点知识】
一.Struts21.1.Struts2的概念Struts2是一个用来开发MVC应用程序的框架,它提供了Web应用程序开发过程中的一些常见问题的解决方案: ->对来自用户的输入数据进行合法 ...
- 应用安全 - CMS - vBulletin漏洞汇总
SSV-15384 Date: 2004.11 漏洞类别: SQL 注入 SSV-15476 Date: 2005.2 漏洞类别: RCE SSV-15482 Date: 2005.2 类型: RCE ...
- HTML5实现绘制几何图形
HTML5新增了一个<canvas.../>属性.该元素自身并不绘制图形,只是相当于一张空画布.如果开发者需要向<canvas.../>上绘制图形则必须使用JavaScript ...