A - Peer Review

Water.

 #include <bits/stdc++.h>
using namespace std; int t, n; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = ; i <= n; ++i) printf("0%c", " \n"[i == n]);
}
return ;
}

B - Boring Game

Unsolved.

C - Enigma Machine

Unsolved.

D - Number Theory

Unsolved.

E - Chasing

Solved.

题意:两个人在一个二维平面上,刚开始两个人在第二象限或者第三象限,A跑到Y轴B就不能追了,B的速度是A的K倍,求B能否追到B

思路:k < 0 那么必然不行

k == 0 判断是不是在同一高度,如果是判断起始位置

k > 0  假设y轴上存在某个点 使得A B 能够在该点相遇,列方程求解

 #include<bits/stdc++.h>

 using namespace std;

 double xa, xb, ya, yb, k;

 int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%lf %lf %lf %lf %lf", &xa, &ya, &xb, &yb, &k);
if(k < 1.0)
{
puts("N");
}
else if(k == 1.0)
{
if(ya != yb) puts("N");
else if(xb < xa) puts("N");
else puts("Y");
}
else
{
double a = k * k - 1.0;
double b = -2.0 * k * k * ya + 2.0 * yb;
double c = k * k * xa * xa - xb * xb + k * k * ya * ya - yb * yb;
double d = b * b - 4.0 * a * c;
if(d >= ) puts("N");
else puts("Y");
}
}
return ;
}

F - Carrot Gathering

Unsolved.

G - Virtual Singers

Upsolved.

题意:

H - How Many Palindromes

Unsolved.

题意:

有$n个A数和m个B数 m <= n,对每个B数都匹配一个A数,使得\sum_{i = 1}^{i = m} |B[i] - A[i]| 最小$

思路:

考虑费用流的思想,维护三个堆

将$A、B 数放在一起排序,然后从左往右枚举$

$如果当前数是A$

  如果左边有未匹配的$B_1数,那么与之匹配即可,此操作不用考虑反悔操作$

  $因为假如有另一个B_2,使得B_2 与 这个A匹配更优$

  那么后面必然要有另一个$A_2 来匹配这个B_1 $

  $贡献是 A_2 - B_1 + B_2 - A_1 这个式子显然小于 A_2 - B_2 + A_1 - B_1$

  因为这四个数字存在大小关系

  $A_2 - B_1 大于 A_2 - B_2 + A_1 - B_1$

  如果左边没有未匹配的$B_1数,那么考虑B的反悔操作是否更优$

  $更优的话就反悔并且将代价取反并算上A往右匹配的贡献放入堆Q_A中, 相当于反悔操作$

$如果当前数是B$

  $如果左边有未匹配的A数,那么与之匹配,并且将代价取反并且算上B往右匹配的贡献放入堆Q_C中$

  否则放入堆$Q_B$中表示还未匹配

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 100010
int t, n, m; ll x;
struct node
{
ll v; int Type;
node () {}
node (ll v, int Type) : v(v), Type(Type) {}
bool operator < (const node &r) const { return v < r.v; }
}arr[N << ];
priority_queue <ll, vector <ll> , greater <ll> > A, B, C; int main()
{
scanf("%d", &t);
while (t--)
{
while (!A.empty()) A.pop();
while (!B.empty()) B.pop();
while (!C.empty()) C.pop();
scanf("%d%d", &n, &m);
for (int i = ; i <= n; ++i)
{
scanf("%lld", &x);
arr[i] = node(x, );
}
for (int i = ; i <= m; ++i)
{
scanf("%lld", &x);
arr[n + i] = node(x, );
}
sort(arr + , arr + + n + m);
ll res = ;
for (int i = ; i <= n + m; ++i)
{
if (arr[i].Type == )
{
if (!A.empty())
{
x = A.top(); A.pop();
res += arr[i].v + x;
C.push(-x - * arr[i].v);
}
else
B.push(-arr[i].v);
}
else
{
if (!B.empty())
{
x = B.top(); B.pop();
res += arr[i].v + x;
}
else if (!C.empty())
{
x = C.top();
if (arr[i].v + x < )
{
C.pop();
res += arr[i].v + x;
A.push(-x - * arr[i].v);
}
else
A.push(-arr[i].v);
}
else
A.push(-arr[i].v);
}
}
printf("%lld\n", res);
}
return ;
}

I - District Division

Solved.

题意:给出一棵树,求能不能分成$\frac{n}{k}$ 个连通块,使得每块个数为k

思路:如果存在合法分法,那么必然存在某个子树大小为k,DFS下去,再回溯上来判断即可,遇到大小为k的子树就分块

 #include<bits/stdc++.h>

 using namespace std;

 const int maxn = 1e5 + ;

 int n, k;

 int val[maxn];
int fa[maxn];
int vis[maxn];
int cnt;
vector<int>root;
vector<int>G[maxn]; void Init()
{
cnt = ;
root.clear();
for(int i = ; i <= n; ++i)
{
val[i] = vis[i] = ;
fa[i] = i;
G[i].clear();
}
} void DFS(int u, int pre)
{
val[u] = ;
fa[u] = pre;
for(int i = , len = G[u].size(); i < len; ++i)
{
int v = G[u][i];
if(v == pre) continue;
DFS(v, u);
val[u] += val[v];
}
if(val[u] == k)
{
cnt++;
val[u] = ;
root.push_back(u);
}
} void DFS2(int u, int pre)
{
if(vis[u]) return ;
vis[u] = ;
printf("%d%c", u, " \n"[cnt == k]);
cnt++;
for(int i = , len = G[u].size(); i < len; ++i)
{
int v = G[u][i];
if(v == pre) continue;
DFS2(v, u);
}
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d %d", &n, &k);
Init();
for(int i = ; i < n; ++i)
{
int u, v;
scanf("%d %d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
DFS(, -);
if(cnt != n / k)
{
puts("NO");
continue;
}
puts("YES");
for(int i = , len = root.size(); i < len; ++i)
{
cnt = ;
DFS2(root[i], fa[root[i]]);
}
}
return ;
}

J - Good Permutation

Solved.

题意:每次能够交换相邻两个数,求最少交换次数使得满足题目给出的序列条件

思路:通过枚举每次在第一位的数,从而递推下一种状态,比如12345推出51234即加上5移到第一位的步数再减去5带来的贡献

 #include<bits/stdc++.h>

 using namespace std;

 typedef long long ll;

 const int maxn = 1e5 + ;

 int n;
int arr[maxn];
int pos[maxn];
int a[maxn]; int lowbit(int p)
{
return p & (-p);
} void update(int p)
{
while(p <= n)
{
a[p]++;
p += lowbit(p);
}
} int query(int p)
{
int res = ;
while(p)
{
res += a[p];
p -= lowbit(p);
}
return res;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
ll ans = ;
for(int i = ; i <= n; ++i) a[i] = ;
for(int i = ; i <= n; ++i)
{
scanf("%d", arr + i);
pos[arr[i]] = i;
}
for(int i = n; i >= ; --i)
{
ans += query(arr[i] - );
update(arr[i]);
}
ll tmp = ans;
for(int i = ; i <= n; ++i)
{
tmp = tmp + n - pos[i] - (pos[i] - );
ans = min(ans, tmp);
}
printf("%lld\n", ans);
}
return ;
}

ZOJ Monthly, June 2018 Solution的更多相关文章

  1. ZOJ Monthly, March 2018 Solution

    A - Easy Number Game 水. #include <bits/stdc++.h> using namespace std; #define ll long long #de ...

  2. ZOJ Monthly, January 2018 Solution

    A - Candy Game 水. #include <bits/stdc++.h> using namespace std; #define N 1010 int t, n; int a ...

  3. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)

    题目链接  ZOJ Monthly, March 2018 Problem G 题意  给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...

  4. ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)

    题目链接  ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...

  5. ZOJ Monthly, March 2018 题解

    [题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...

  6. ZOJ Monthly, January 2018 训练部分解题报告

    A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...

  7. ZOJ Monthly, June 2014 月赛BCDEFGH题题解

    比赛链接:点击打开链接 上来先搞了f.c,,然后发现状态不正确,一下午都是脑洞大开,, 无脑wa,无脑ce...一样的错犯2次.. 硬着头皮搞了几发,最后20分钟码了一下G,不知道为什么把1直接当成不 ...

  8. ZOJ Monthly, January 2018

    A 易知最优的方法是一次只拿一颗,石头数谁多谁赢,一样多后手赢 #include <map> #include <set> #include <ctime> #in ...

  9. ZOJ Monthly, March 2018

    A. Easy Number Game 贪心将第$i$小的和第$2m-i+1$小的配对即可. #include<cstdio> #include<algorithm> usin ...

随机推荐

  1. linux下更改vncserver的密码

    Linux下VNC配置多个桌面和修改密码 1:vncserver2:iptables -I INPUT -p tcp --dport 5901 -j ACCEPT   客户端方式3:iptables ...

  2. iOS - UIImageView - how to handle UIImage image orientation

    本文转载至 http://stackoverflow.com/questions/8915630/ios-uiimageview-how-to-handle-uiimage-image-orienta ...

  3. C# EMS Client

    从 C# 客户端连接 Tibco EMS 下面例子简要介绍 C# 客户端怎样使用 TIBCO.EMS.dll 来连接 EMS 服务器. using System; using System.Diagn ...

  4. SPOJ - DQUERY

    题目链接:传送门 题目大意:一个容量 n 的数组, m次询问,每次询问 [x,y]内不同数的个数 题目思路:主席树(注意不是权值线段树而是位置线段树) 也就是按一般线段树的逻辑来写只是用主席树实现而已 ...

  5. window自带字体

    一.在默认情况下, Windows 默认提供下列字体: Windows 95/98/98SE 宋体.黑体.楷体_GB2312.仿宋_GB2312 Windows XP/2000/2003/ME/NT ...

  6. Egret的一些性能优化

    Egret的性能优化不知道在哪里啊,主要参考Laya的性能优化,都差不多 一.性能统计面板 index.html页面设置data-show-fps=true打开性能面板 性能统计面板说明 Egret没 ...

  7. 【BZOJ1453】[Wc]Dface双面棋盘 线段树+并查集

    [BZOJ1453][Wc]Dface双面棋盘 Description Input Output Sample Input Sample Output HINT 题解:话说看到题的第一反应其实是LCT ...

  8. jquery插件方式实现table查询功能

    1.写插件部分,如下: ;(function($){ $.fn.plugin = function(options){ var defaults = { //各种属性,各种参数 } var optio ...

  9. .NET截取指定长度字符超出部分以"..."代替

    /// <summary> /// 将指定字符串按指定长度进行剪切, /// </summary> /// <param name= "Str "&g ...

  10. Java学习记录-Lambda表达式示例

    List<Integer> userIds=userInfoList.stream().map(m->m.getUserId()).collect(Collectors.toList ...