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 ...
随机推荐
- POST上传多张图片配合Django接受多张图片
POST上传多张图片配合Django接受多张图片 本地:POST发送文件,使用的是files参数,将本地的图片以二进制的方式发送给服务器. 在这里 files=[("img",op ...
- git && github 相关
权限问题(error: The requested URL returned error: 403 Forbidden while accessing):1. 将自己机器的ssh public key ...
- webpack配置之webpack.config.js文件配置
webpack配置之webpack.config.js文件配置 webpack.config.js webpack resolve 1.总是手动的输入webpack的输入输出文件路径,是一件非常繁琐 ...
- python - 标准库:traceback模块
traceback 模块: 允许你在程序里打印异常的跟踪返回 (Traceback)信息, 类似未捕获异常时解释器所做的. import traceback try: raise SyntaxErro ...
- C# 自定义集合类
.NET中提供了一种称为集合的类型,类似于数组,将一组类型化对象组合在一起,可通过遍历获取其中的每一个元素 本篇记录一个自定义集合的小实例.自定义集合需要通过实现System.Collections命 ...
- Python Module_os_操作系统
目录 目录 前言 软件环境 os模块内建属性 osname 获取执行平台的类型 oslinesep 输出当前平台使用的行终止符 ossep 输出操作系统特定的路径分隔符 ospathsep 输出用于分 ...
- 阶段3 1.Mybatis_01.Mybatis课程介绍及环境搭建_01.mybatis课程介绍
- python每日一练:0012题
第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好 ...
- 深入理解java:1.3. 垃圾收集
Java垃圾收集(Garbage Collection,GC) 某一个时点,一个对象如果有一个以上的引用(Rreference)指向它,那么该对象就为活着的(Live), 否则死亡(Dead),视为垃 ...
- linux 正则表达式 使用grep命令
最常应用正则表达式命令是 awk sed grep [root@MongoDB ~]# cat mike.log I am mike! I like linux. I like play footba ...