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 ;
}

最新文章

  1. 用chrome来映射查找样式对应的sass
  2. Codeforces Round #109 (Div. 2) E. Double Profiles hash
  3. 通过udl文件得到连接字符串
  4. mysql视图的作用(详细)
  5. Android 样式
  6. Qt核心剖析: moc
  7. 用asio的定时器实现带超时的connect,备忘
  8. POJ 3041 Asteroids(匈牙利+邻接表)
  9. 异常处理try-catch-finally笔记
  10. [国嵌攻略][163][linux-usb软件系统架构]
  11. 消息中间件kafka+zookeeper集群部署、测试与应用
  12. thymeltesys-基于Spring Boot Oauth2的扫码登录框架
  13. nuxt
  14. PHP和PHP-FPM 配置文件优化
  15. Java IO编程全解(二)——传统的BIO编程
  16. LeetCode——727.Minimum Window Subsequence
  17. 【PAT】B1065 单身狗(25 分)
  18. 赵炯博士《Linux内核完全注释》
  19. 微信小程序之画布
  20. web.xml文件初始化过程

热门文章

  1. java生成二维码的几种方式
  2. jsp四种属性范围
  3. jprofiler监控wls&amp;was配置
  4. [Python]ctypes+struct实现类c的结构化数据串行处理
  5. xshell6,xftp下载
  6. Delphi XE2 之 FireMonkey 入门(45Finally) - 结题与问题
  7. 你知道 Git 是如何做版本控制的吗?(转)
  8. 阶段2 JavaWeb+黑马旅游网_15-Maven基础_第5节 使用骨架创建maven的java工程_18maven的java工程取mysql数据库
  9. Activity启动流程(三)
  10. idea把java web项目打成war包