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 ...
随机推荐
- FLV文件格式分析(附源码)
FLV文件主要由两部分组成:Header和Body. 1. Header header部分记录了flv的类型.版本等信息,是flv的开头,一般都差不多,占9bytes.具体格式如下: 文件类型 3 b ...
- 通过scrapy,从模拟登录开始爬取知乎的问答数据
这篇文章将讲解如何爬取知乎上面的问答数据. 首先,我们需要知道,想要爬取知乎上面的数据,第一步肯定是登录,所以我们先介绍一下模拟登录: 先说一下我的思路: 1.首先我们需要控制登录的入口,重写star ...
- leetcode 72.编辑距离(dp)
链接:https://leetcode-cn.com/problems/edit-distance/submissions/ 设dp[i][j]表示串s1前i个字符变换成串s2前j个字符所需要的最小操 ...
- poj 3281Dining(网络流 拆点)
题目链接:http://poj.org/problem?id=3281 题目大意:John养了N只奶牛,他为奶牛准备了F个食物和D个饮料,但是每只奶牛只对其中的一些饮料和食物感兴趣,现在请制定一些方案 ...
- thinkphp一些经常用到的标签
volist标签(用于模板中的数组循环输出) //length:循环多少次 {volist name='list' id='vo' length='4'} <span>{$vo.name} ...
- rabbitmq 命令行与控制台
命令行和管控台 rabbitmqctl stop_app 关闭应用 rabbitmqctl start_app 打开应用 rabbitmqctl status 节点状态 rabbitmqctl add ...
- js中map和filter方法,以及search方法
链接:https://blog.51cto.com/11871779/2126561 search方法: 介绍: search() 方法用于检索字符串中指定的子字符串,或检索与正则表达式相匹配的子字符 ...
- 数据库备份与还原:mysqldump,source
*数据库备份* 1.备份方法一:适用于myslam表: 直接将tb_name.frm.tb_name.myd.tb_name.myi三个文件保存,备份即可. 需要的时候直接解压到,移动到相应的数据库目 ...
- jmeter的BeanShell Sampler使用--导入第三方jar包
实现目的 测试接口的过程中,可能有时需要用到第三方jar包来生成一些测试数据,此时我们就可以通过BeanShell来调用自己编写的工具类,来对jmeter的功能进行扩展,以满足测试需要. 脚本实现 在 ...
- 启动MySQL5.7时报错:initialize specified but the data directory has files in it. Aborting.
启动MySQL5.7时报错:initialize specified but the data directory has files in it. Aborting 解决方法: vim /etc/m ...