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寒假训练一的更多相关文章

  1. FZU ICPC 2020 寒假训练 4 —— 模拟(一)

    P1042 乒乓球 题目背景 国际乒联现在主席沙拉拉自从上任以来就立志于推行一系列改革,以推动乒乓球运动在全球的普及.其中11分制改革引起了很大的争议,有一部分球员因为无法适应新规则只能选择退役.华华 ...

  2. 寒假训练第九场 Brocard Point of a Triangle

    题意:求布洛卡点坐标 思路:直接利用布洛卡点的性质.http://pan.baidu.com/s/1eQiP76E #include<cstdio> #include<cstring ...

  3. FJUT2017寒假训练二题解

    A题 题意:让你找出唯一的一个四位数,满足对话时的要求. 思路:因为是4位数,可以直接从1000-9999遍历一遍,判断是否有唯一的数能满足所有条件,如果不是唯一的或者没有满足条件的数就输出Not s ...

  4. J - Abbott's Revenge 搜索 寒假训练

    题目 题目大意:这个题目就是大小不超过9*9的迷宫,给你起点终点和起点的方向,让你进行移动移动特别之处是不一定上下左右都可以,只有根据方向确定可以走的方向.思路:需要写一个读入函数,这个需要读入起点, ...

  5. 寒假训练——搜索——C - Robot

    The Robot Moving Institute is using a robot in their local store to transport different items. Of co ...

  6. 寒假训练——搜索 K - Cycle

    A tournament is a directed graph without self-loops in which every pair of vertexes is connected by ...

  7. HRBUST - 2347 - 递归画图 - vj大一上寒假训练2.11

    其他题可由本题变形得到. 思路:利用坐标dfs搜索. 注意:1,初始化.2,坐标实时更新(x,y) 代码: #include<iostream> #include<cstdio> ...

  8. 寒假训练——搜索 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 ...

  9. 寒假训练——搜索 E - Bloxorz I

    Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...

随机推荐

  1. Docker 基本命令和使用

    Docker 基本命令 systemctl start docker : 启动 Docker systemctl stop docker : 停止 Docker systemctl restart d ...

  2. NIO-BufferAPI

    一 核心要素 capacity (容量):不能为负,不可更改:就是buffer的长度(buffer.length) limit (限制):指第一个不可被读入缓冲区元素的位置:不可为负,若positio ...

  3. 1.BMap(百度地图)第二次加载显示不全

    问题: bmap第一次加载显示没问题: 第二次 再次加载这个页面时,地图的显示出现了问题: . 分析问题出现原因:你要确保dom创建后且处于显示状态(即display不能为none)才能再次初始化地图 ...

  4. C#中发ref和out

    ref--Reference  引用 out--Output   输出 相同点: 代入参数时,前面必须加上ref  out 关键字 都能在方法内对外部的变量的值进行更改 不同点: ref代入的参数必须 ...

  5. CSS学习(4)常见样式声明

    1.文本 color 文字颜色 预设值:定义好的单词,如red blue 光学的三原色(红,绿,蓝),如 rgb(32,45,255) HEX十六进制,如#008CFF(#112233可以简写为#12 ...

  6. 「JSOI2015」isomorphism

    「JSOI2015」isomorphism 传送门 我们还是考虑树哈希来判同构. 但是我们需要使用一些特殊的手段来特殊对待假节点. 由于是无向树,我们首先求出重心,然后以重心为根跑树哈希. 此处我们不 ...

  7. 通过颜色绘制图片UIImage

    + (UIImage *)clearImageView { UIColor *color=[UIColor clearColor]; CGRect rect =CGRectMake(,,,); UIG ...

  8. 2、json教程

    JSON(JavaScript)对象表示法是一种轻量级的基于文本的开放标准, 被设计用于可读的数据交换, 约定使用JSON的程序包括 C C++ Java Python Perl     总结 JSO ...

  9. Red Hat 7.4 安装laravel框架 基于xampp集成环境

    一.安装xampp 1.下载xampp安装包:xampp-linux-x64-7.1.10-0-installer.run 2.在安装包目录下运行命令: ./xampp-linux-x64-7.1.1 ...

  10. MyBatis操作mysql数据库查询出来是时间戳的问题

    在pojo类中用java.sql.Date接收就能正常显示