atcoder 076
日本人的比赛
C:如果两个数差了大于1无解,否则分类讨论
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = , mod = ;
int n, m;
ll a[N];
ll power(ll x, ll t)
{
ll ret = ;
for(; t; t >>= , x = x * x % mod)
if(t & )
ret = ret * x % mod;
return ret;
}
int main()
{
scanf("%d%d", &n, &m);
if(n < m) swap(n, m);
if(n - m != && n - m != )
{
puts("");
return ;
}
a[] = ;
for(int i = ; i <= n + ; ++i)
a[i] = a[i - ] * (ll)i % mod;
if(n == m)
printf("%lld\n", 2ll * a[n] % mod * a[m] % mod);
else
printf("%lld\n", a[n] % mod * a[m] % mod);
return ;
}
D:分别按xy排序,然后分别把相邻的差放进去做最小生成树。因为如果三个点xaxbxc,xa<xb<xc,那么连xa->xb->xc肯定比xa->xc优,也就是说连相邻的肯定最优。因为这n-1条边能构成最小生成树,而且是自己维度最优的,所以只要和最小的y比较就行了,肯定会有解,而且是最优的,因为我们不可能会去用其他的边。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
struct edge {
int u, v;
ll w;
edge(int u, int v, ll w) : u (u), v (v), w (w) {}
};
struct data {
ll x, y;
int id;
} a[N];
int n;
int fa[N];
ll ans;
vector<edge> e;
bool cp(edge x, edge y)
{
return x.w < y.w;
}
bool cp1(data x, data y)
{
return x.x < y.x;
}
bool cp2(data x, data y)
{
return x.y < y.y;
}
int find(int x)
{
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; ++i) fa[i] = i;
for(int i = ; i <= n; ++i)
{
scanf("%lld%lld", &a[i].x, &a[i].y);
a[i].id = i;
}
sort(a + , a + n + , cp1);
for(int i = ; i <= n; ++i)
e.push_back(edge(a[i].id, a[i - ].id, a[i].x - a[i - ].x));
sort(a + , a + n + , cp2);
for(int i = ; i <= n; ++i)
e.push_back(edge(a[i].id, a[i - ].id, a[i].y - a[i - ].y));
sort(e.begin(), e.end(), cp);
for(int i = ; i < e.size(); ++i)
{
if(find(e[i].u) == find(e[i].v))
continue;
ans += e[i].w;
fa[find(e[i].u)] = find(e[i].v);
}
printf("%lld\n", ans);
return ;
}
E:并没有AC,不知道哪里错了。
结论:不全在边框上的整数互相之间肯定能连起来。
只要考虑的是在边框上的点,防止出现ijij的情况,于是用一个栈从顺时针加入,如果加入的点和栈顶是同一种数字,那么弹出,否则加入,最后看栈是否为空。
wa
#include<bits/stdc++.h>
using namespace std;
const int N = ;
struct data {
int x, y, id;
};
int n, r, c, top;
vector<data> v[];
data st[N];
bool cp1(data x, data y)
{
return x.x < y.x;
}
bool cp2(data x, data y)
{
return x.x > y.x;
}
bool cp3(data x, data y)
{
return x.y < y.y;
}
bool cp4(data x, data y)
{
return x.y > y.y;
}
int main()
{
scanf("%d%d%d", &r, &c, &n);
for(int i = ; i <= n; ++i)
{
data a, b; scanf("%d%d%d%d", &a.x, &a.y, &b.x, &b.y);
a.id = b.id = i;
if((a.x == || a.x == c || a.y == || a.y == r) && (b.x == || b.x == c || b.y == || b.y == r))
{
if(a.x == )
v[].push_back(a);
else if(a.y == r)
v[].push_back(a);
else if(a.x == c)
v[].push_back(a);
else if(a.y == )
v[].push_back(a);
if(b.x == )
v[].push_back(b);
else if(b.y == r)
v[].push_back(b);
else if(b.x == c)
v[].push_back(b);
else if(b.y == )
v[].push_back(b);
}
}
sort(v[].begin(), v[].end(), cp3);
sort(v[].begin(), v[].end(), cp1);
sort(v[].begin(), v[].end(), cp4);
sort(v[].begin(), v[].end(), cp2);
st[].id = ;
for(int i = ; i < ; ++i)
for(int j = ; j < v[i].size(); ++j)
{
data x = v[i][j];
// printf("x.id=%d x.x=%d x.y=%d\n", x.id, x.x, x.y);
if(x.id == st[top].id)
--top;
else
st[++top] = x;
}
puts(top == ? "YES" : "NO");
return ;
}
atcoder 076的更多相关文章
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Regular Contest 076
在湖蓝跟衡水大佬们打的第二场atcoder,不知不觉一星期都过去了. 任意门 C - Reconciled? 题意:n只猫,m只狗排队,猫与猫之间,狗与狗之间是不同的,同种动物不能相邻排,问有多少种方 ...
- AtCoder Regular Contest 076 E - Connected?
题目传送门:https://arc076.contest.atcoder.jp/tasks/arc076_c 题目大意: 给定一个\(R×C\)的矩阵,然后给定\(N\)对点,每对点坐标为\((X_{ ...
- 【题解】 AtCoder ARC 076 F - Exhausted? (霍尔定理+线段树)
题面 题目大意: 给你\(m\)张椅子,排成一行,告诉你\(n\)个人,每个人可以坐的座位为\([1,l]\bigcup[r,m]\),为了让所有人坐下,问至少还要加多少张椅子. Solution: ...
- AtCoder Regular Contest 076 F - Exhausted?
题意: n个人抢m个凳子,第i个人做的位置必须小于li或大于ri,问最少几个人坐不上. 这是一个二分图最大匹配的问题,hall定理可以用来求二分图最大匹配. 关于hall定理及证明,栋爷博客里有:ht ...
- 【AtCoder Regular Contest 076 F】Exhausted (贪心)
Description 机房里有M台电脑排成一排,第i台电脑的坐标是正整数i. 现在有N个OIer进入了机房,每个OIer需要一台电脑来学tui习ji,同时每个OIer对自己电脑所处的坐标范围有一个要 ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...
- AtCoder Regular Contest 082
我都出了F了……结果并没有出E……atcoder让我差4分上橙是啥意思啊…… C - Together 题意:把每个数加1或减1或不变求最大众数. #include<cstdio> #in ...
随机推荐
- swift中使用对象归档进行数据本地
对象归档是ios持久化中的其中一种,也是很常用的一种.现在来看看swift是如何实现的.实现要点1),必须实现NSCoding的协议 import UIKit let path=(NSSearchPa ...
- linux下C/C++程序的内存布局
内核空间和用户空间: 我们在编写程序时使用的内存空间叫虚拟内存,程序在运行时,要完成虚拟内存到物理内存的转换.假如在32位环境上,理论上我们可以使用的虚拟内存空间是4GB,但实际上这4GB并不能完全给 ...
- 把 web 项目部署到 Linux 服务器上
1.打开 eclipse,在已经完成的 web 项目上面点击右键,选择 export,然后选择导出成 war 包. 以部署 SMBMS 项目为例 2.项目打包成 war ,选择项目导出到的位置. ...
- MySql报Packet for query is too large错误
mysql中执行sql的时候报以下错误:Packet for query is too large (1354 > 1024) 原因是mysql一次接收的报文太长,需要调整服务器参数max_al ...
- 洛谷 1821 [USACO07FEB]银牛派对Silver Cow Party
[题解] 其实解法 #include<cstdio> #include<cstring> #include<algorithm> #define LL long l ...
- ds020507
芯片输出端不加负载的时候,芯片的输出电压是9点多伏. 加上大的负载,芯片发热,电压接近输入电压. 正常负载,芯片输出7.0几伏. 版权声明:本文为博主原创文章,未经博主允许不得转载.
- 关于 startup_stm32f10x_hd.s 这个文件的一些说明
关于 startup_stm32f10x_hd.s 这个文件的一些说明 startup_stm32f10x_hd.s 是一个启动文件,里面是使用汇编语言写好的基本程序,当STM32 芯片上电启动的时候 ...
- 在此计算机中仅有部分visual studio2010产品已升级到SP1,只有全部升级,产品才能正常运行
先说废话: 本人机子刚装系统Win10 专业版 1709 开始安装vs2010的时候中途报错了,有一个什么驱动不兼容,被我给关闭了,继续安装完,然后找不到vs的启动快捷方式,开始里面没有,于是我开始修 ...
- linux 简单实用小操作
mysql改密码 通过root以后,(root密码忘记就没法了) alter user username@'%' identified by 'password' 端口被占用 sudo fuser - ...
- [luoguP2983] [USACO10FEB]购买巧克力Chocolate Buying(贪心)
传送门 按价格排序后贪心 ——代码 #include <cstdio> #include <iostream> #include <algorithm> int n ...