yp寒假训练一
19年东北四省省赛
做了J G C
补了E H
J签到题
G
题意:
给n个正方形的两个斜对角点坐标,问最小的移动可以重叠(移动上下左右一格)
思路:
一开始想的是中心pos移动,但是可能有小数,而且半径长度不知,可能有包含关系。
然后发现题目没说一定要某一个正方形移动的最小步数,那之间转换为点在面里面的移动最小,取中间的两个上下斜对角坐标就行了
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<queue>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
const int maxn=1e5+;
struct node{
int x,y,xx,yy;
}a[maxn];
int t,n;
int x[maxn<<],y[maxn<<];
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int xt=,yt=;
for(int i=;i<n;i++){
scanf("%d%d%d%d",&a[i].x,&a[i].y,&a[i].xx,&a[i].yy);
x[xt++]=a[i].x,x[xt++]=a[i].xx;
y[yt++]=a[i].y,y[yt++]=a[i].yy;
}
sort(x,x+xt);
sort(y,y+yt);
int zx=x[xt/],zy=y[yt/];
ll sum=;
for(int i=;i<n;i++){
if(zx<a[i].x || zx>a[i].xx){
sum+=(ll)min(abs(a[i].x-zx),abs(a[i].xx-zx));
}
if(zy<a[i].y || zy>a[i].yy){
sum+=(ll)min(abs(a[i].y-zy),abs(a[i].yy-zy));
}
}
printf("%lld\n",sum);
}
return ;
}
C
题意:
给n条直线,问有多少两两相交的线,重叠也算相交的线
思路:
总量n*(n-1)/2-平行的数量
一开始算斜率,但因为斜率的精确度,wa,然后想了用gcd或者用逆元
最后用了map存y/x的最小分数yy和xx,在特判一下重叠的
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<queue>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
const int maxn=1e5+;
int n,t;
ll a,b,c,d;
ll gcd(ll a,ll b){
return b==?a:gcd(b,a%b);
}
struct node{
ll x,y;
node(){}
node(ll xx,ll yy):x(xx),y(yy){}
bool operator<(const node &b)const
{
if(x==b.x)
return y<b.y;
else
return x<b.x;
}
};
struct node1{
ll x,y,chong;
node1(){}
node1(ll xx,ll yy,ll cc):x(xx),y(yy),chong(cc){}
bool operator<(const node1 &b)const
{
if(x==b.x){
if(y==b.y){
return chong<b.chong;
}
return y<b.y;
}
else
return x<b.x;
}
};
map<node,ll>mp;
map<node1,ll>cd;
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d",&n);
ll zong=(ll)n*(n-)/;
for(int i=;i<n;i++){
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
ll xx=a-c,yy=b-d;
ll gd=gcd(xx,yy);
ll x=xx/gd,y=yy/gd;
ll f=x*b+y*a;
mp[node(x,y)]++;
zong-=mp[node(x,y)];
cd[node1(x,y,f)]++;
zong+=cd[node1(x,y,f)];
}
printf("%lld\n",zong);
mp.clear(),cd.clear();
}
return ;
}
E
题意:
给n个点,n-1条边,每条边都有权重,每个边形成一个最小生成树,形成线图
思路:
算每个点的贡献值,这个点的出度小于二,无贡献,大于二,就是相邻的边加一起,在最小的那个边*(相邻边数-2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int maxn=;
struct node
{
int v,w;
node(){}
node(int n,int m):v(n),w(m){}
bool operator < (const node &r)const{
return w<r.w;
}
};
vector<node>G[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)G[i].clear();
for(int i=;i<=n-;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
G[u].push_back(node(v,w));
G[v].push_back(node(u,w));
}
ll ans=;
for(int i=;i<=n;i++){
sort(G[i].begin(),G[i].end());
int minn=0x3f3f3f3f;
int degree=G[i].size();
for(int j=;j<degree;j++){
ans+=G[i][j].w;
minn=min(minn,G[i][j].w);
}
ans+=(ll)minn*(degree-);
}
printf("%lld\n",ans);
}
return ;
}
H:
https://www.cnblogs.com/luoyugongxi/p/12191649.html
yp寒假训练一的更多相关文章
- FZU ICPC 2020 寒假训练 4 —— 模拟(一)
P1042 乒乓球 题目背景 国际乒联现在主席沙拉拉自从上任以来就立志于推行一系列改革,以推动乒乓球运动在全球的普及.其中11分制改革引起了很大的争议,有一部分球员因为无法适应新规则只能选择退役.华华 ...
- 寒假训练第九场 Brocard Point of a Triangle
题意:求布洛卡点坐标 思路:直接利用布洛卡点的性质.http://pan.baidu.com/s/1eQiP76E #include<cstdio> #include<cstring ...
- FJUT2017寒假训练二题解
A题 题意:让你找出唯一的一个四位数,满足对话时的要求. 思路:因为是4位数,可以直接从1000-9999遍历一遍,判断是否有唯一的数能满足所有条件,如果不是唯一的或者没有满足条件的数就输出Not s ...
- J - Abbott's Revenge 搜索 寒假训练
题目 题目大意:这个题目就是大小不超过9*9的迷宫,给你起点终点和起点的方向,让你进行移动移动特别之处是不一定上下左右都可以,只有根据方向确定可以走的方向.思路:需要写一个读入函数,这个需要读入起点, ...
- 寒假训练——搜索——C - Robot
The Robot Moving Institute is using a robot in their local store to transport different items. Of co ...
- 寒假训练——搜索 K - Cycle
A tournament is a directed graph without self-loops in which every pair of vertexes is connected by ...
- HRBUST - 2347 - 递归画图 - vj大一上寒假训练2.11
其他题可由本题变形得到. 思路:利用坐标dfs搜索. 注意:1,初始化.2,坐标实时更新(x,y) 代码: #include<iostream> #include<cstdio> ...
- 寒假训练——搜索 G - Xor-Paths
There is a rectangular grid of size n×mn×m . Each cell has a number written on it; the number on the ...
- 寒假训练——搜索 E - Bloxorz I
Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...
随机推荐
- POJ 3177 Redundant Paths (tarjan边双连通分量)
题目连接:http://poj.org/problem?id=3177 题目大意是给定一些牧场,牧场和牧场之间可能存在道路相连,要求从一个牧场到另一个牧场要有至少两条以上不同的路径,且路径的每条pat ...
- bistoury建库建表(一)
bistoury DROP TABLE IF EXISTS bistoury_app; CREATE TABLE bistoury_app( id INT UNSIGNED auto_incremen ...
- Python - 标准库部分函数、类的大致实现(持续更新)
all() def all(iterable): for element in iterbale: if not element: return False return True any() def ...
- 建立Web Service 接口及调用
WEB SERVICE 接口: [WebMethod] public string MaterialRequest(string jsonText) { string WorkNo; string P ...
- 左偏树(p1456) 比较模板的一道题
题意:有n只猴子,m个操作,每一个操作,会让这两堆猴子里的最大的两只打架,打完之后,自身权值减半,然后他们会成为朋友 也就是会属于同一棵树,细节:如果选出的猴子在同一堆,就输出-1,然后下一个操作,不 ...
- 前端知识之html
html介绍 web服务器的本质 import socket sk=socket.socket() sk.bind(('127.0.0.1'.8080)) sk.listen(5) while Tru ...
- NUMPY的学习之路(2)——索引,合并,分割,赋值
一.索引 1.1numpy数组的转置 A=np.arange(3,15).reshape(3,4) print(A) print(A[2][0]) print(A[2,1]) print(A[2,:] ...
- Atcoder Beginner Contest152F(DFS+状压DP)
二维状压写成一维状压,省略加上第i条边这一维 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace st ...
- 存储引擎:engine
1.表类型: 默认的服务器表类型,通过my.ini文件可以手动修改配置:default-storage- engine=INNODB 在创建表,或者编辑表时,可以指定表的存储引擎: 语法:engine ...
- 微信小程序云函数中有以下未安装的依赖,如果未安装即全量上传
云函数中有以下未安装的依赖,如果未安装即全量上传 在新建的云函数,右击终端打开->cmd,安装依赖 npm install --production 依赖安装成功之后,文件里面会出现 packa ...