K - Parallelogram Counting解题报告(来自网络)

此博客介绍了一个用于计算平面内给定点构成平行四边形数量的算法,包括输入处理、输出结果以及代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

K - Parallelogram Counting
Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

There are n distinct points in the plane, given by their integer coordinates. Find the number of parallelograms whose vertices lie on these points. In other words, find the number of 4-element subsets of these points that can be written as {A, B, C, D} such that AB || CD, and BC || AD. No four points are in a straight line.

Input

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases. It is followed by the input data for each test case. 
The first line of each test case contains an integer n (1 <= n <= 1000). Each of the next n lines, contains 2 space-separated integers x and y (the coordinates of a point) with magnitude (absolute value) of no more than 1000000000. 

Output

Output should contain t lines. 
Line i contains an integer showing the number of the parallelograms as described above for test case i. 

Sample Input

2
6
0 0
2 0
4 0
1 1
3 1
5 1
7
-2 -1
8 9
5 7
1 1
4 8
2 0
9 8

Sample Output

5
6

#include<memory.h>
#include<stdlib.h>
#include<stdio.h>
#define MAX 1000
#define HMAX  0x3fffff
#define P 0x1fffff
//将每个中点的x,y都记录下来,如果
//同时记录拥有这个中点的线段的个数
struct Point{
	int x;
	int y;
	int count;
	int next;
};
Point p[MAX*MAX];
int head[HMAX];
int x[MAX],y[MAX];
int main()
{
	int t,n;
	int zz,xx,yy,xtmp,ytmp,ptr,res,h;
	bool flag;
	scanf("%d",&t);
	while(t--)
	{
		ptr = 1;
		res = 0;
		memset(head,0,sizeof(head));
		memset(p,0,sizeof(p));
		scanf("%d",&n);
		for(int i = 0; i < n; i++)
		{
			scanf("%d%d",&xtmp,&ytmp);
			for(int j = 0; j < i; j++)
			{
				flag = true;
				xx = xtmp + x[j];
				yy = ytmp + y[j];
				//h = xx & P + yy & P; --用这种方法反而更慢...
				//哈希中点坐标之和
				h = abs(xx + yy)%HMAX;
				zz = head[h];
				while(zz){
					if(p[zz].x == xx && p[zz].y == yy){
						p[zz].count++;
						res+=p[zz].count;
						flag = false;
						break;
					}
					else
						zz = p[zz].next;
				}
				//插入新的中点
				if(flag)	{
					p[ptr].x = xx;
					p[ptr].y = yy;
					p[ptr].next = head[h];
					head[h] = ptr++;
				}
			}
			x[i] = xtmp;
			y[i] = ytmp;
		}
		printf("%d/n",res);
	}
	return 0;
}




<think>嗯,用户之前问过关于进度条末端变成平行四边形尖角的问题,我给出了使用CSS伪元素和变形来实现的方法。现在用户反馈说尖角的渐变色有问题,可能颜色没有正确继承或者渐变方向不对。 首先,我需要回顾之前的解决方案。用户使用了::after伪元素,并尝试通过background: inherit或background-image: inherit来继承进度条的渐变色。但根据用户的代码,注释显示他们尝试了这两种方法,但可能没有生效。 问题可能出在继承背景渐变的方式上。因为进度条的背景是一个线性渐变,而伪元素默认可能只继承父元素的背景属性,但父元素的背景可能被应用到整个进度条,而不是当前进度的部分。此外,使用background-image: inherit可能无法正确获取到动态生成的渐变,特别是在Vue中,可能因为作用域或样式隔离的问题,导致伪元素无法访问到父元素的背景。 接下来,我需要考虑如何让伪元素的背景与进度条的渐变保持一致。可能的解决方案包括使用CSS变量来传递渐变色,或者通过JavaScript动态获取计算后的样式并应用到伪元素上。不过,后者可能比较复杂,尤其是在Vue组件中,需要处理响应式更新。 另外,用户使用了/deep/选择器,这在Vue的Scoped CSS中可能已经被弃用,可能需要改用::v-deep或者其他方法。但用户的问题主要是颜色继承,所以先聚焦于此。 渐变方向也是一个问题。进度条的渐变是从左到右的,而伪元素被倾斜后,渐变的轴可能不会自动适应,导致颜色过渡不匹配。需要调整伪元素的背景大小和位置,使其与进度条的渐变对齐。 可能的解决方案是:将伪元素的背景设置为与进度条相同的渐变,并调整背景的大小和位置,使其看起来是连续的。例如,将背景大小设置为进度条容器的宽度加上伪元素的宽度,然后定位到右侧,这样渐变更连贯。 此外,检查是否正确继承了渐变色。如果进度条的渐变色是通过内联样式或动态绑定的,伪元素可能需要显式地设置相同的渐变值,而不是依赖继承。例如,在Vue中,可以将stroke-color绑定的渐变对象转换为CSS渐变字符串,并应用到伪元素的样式中。 还需要考虑浏览器兼容性问题,比如transform和渐变之间的渲染差异,以及伪元素是否正确覆盖了进度条的末端。可能需要调整伪元素的宽度、倾斜角度和位置,确保无缝衔接。 最后,建议用户检查DOM结构和计算后的样式,确认伪元素是否应用了正确的背景,并逐步调试渐变参数,调整背景位置和大小,直到视觉效果符合预期。</think>针对进度条尖角渐变色不匹配的问题,这里提供详细解决方案: --- ### **一、问题根源分析** 1. **背景继承失效**:直接使用 `background: inherit` 无法正确继承线性渐变 2. **坐标系偏移**:`skewX` 变形导致渐变方向错位 3. **尺寸不匹配**:伪元素与主进度条的渐变范围不一致 --- ### **二、修复方案** **步骤1:精确传递渐变色值**(修改Vue组件) ```vue <a-progress :stroke-color="gradientConfig" ... ></a-progress> <script> // 在组件data中定义渐变配置 data() { return { gradientConfig: { '0%': '#6a9e81', '100%': '#92e391', // 添加中间过渡色 '50%': '#7fb58d' } } } </script> ``` **步骤2:动态生成CSS渐变**(关键修复) ```css /* 平行四边形尖角 */ /deep/ .parallelogram-progress .ant-progress-bg::after { /* 删除background-image: inherit */ background-image: linear-gradient( to right, #6a9e81 0%, /* 手动同步渐变色值 */ #7fb58d 50%, #92e391 100% ); background-size: calc(100% + 15px) 100%; /* 扩展渐变区域 */ background-position: left center; /* 对齐主进度条 */ } ``` --- ### **三、动态同步方案**(适用于动态颜色) ```vue <a-progress :style="{ '--start-color': '#6a9e81', '--mid-color': '#7fb58d', '--end-color': '#92e391' }" ></a-progress> <style> /* 动态渐变尖角 */ .parallelogram-progress .ant-progress-bg::after { background-image: linear-gradient( to right, var(--start-color) 0%, var(--mid-color) 50%, var(--end-color) 100% ); } </style> ``` --- ### **四、坐标系校准方案** ```css /deep/ .parallelogram-progress .ant-progress-bg::after { transform: translateY(-50%) skewX(-30deg) scaleX(1.2); /* 扩展覆盖变形区域 */ transform-origin: right center; /* 控制变形基点 */ background-repeat: no-repeat; } ``` --- ### **五、最终优化方案** ```css /deep/ .parallelogram-progress { /* 强制开启GPU加速 */ transform: translateZ(0); .ant-progress-bg { &::after { /* 精确渐变定位 */ background: linear-gradient( 75deg, /* 根据实际倾斜角度调整 */ rgba(106,158,129,1) 20%, rgba(146,227,145,1) 80% ); /* 边缘柔化处理 */ filter: blur(0.5px); /* 防止颜色断层 */ backface-visibility: hidden; } } } ``` --- ### **六、注意事项** 1. **颜色同步**:若使用动态颜色,需要通过CSS变量或Style绑定同步到伪元素 2. **角度匹配**:`skewX(-30deg)` 需与渐变方向的 `75deg` 形成互补角度 3. **浏览器差异**:在Safari中可能需要添加 `-webkit-mask-image` 辅助裁剪 4. **性能优化**:避免过度使用模糊滤镜,建议最大不超过1px模糊度 可通过调试工具实时调整这三个参数实现完美匹配:`skew角度`、`渐变方向`、`background-size扩展量`
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值