问题 L: Ruined Square

题目链接

  • 题目描述

  • There is a square in the xy-plane. The coordinates of its four vertices are (x1,y1),(x2,y2),(x3,y3) and (x4,y4) in counter-clockwise order. (Assume that the positive x-axis points right, and the positive y-axis points up.)
    Takahashi remembers (x1,y1) and (x2,y2), but he has forgot (x3,y3) and (x4,y4).
    Given x1,x2,y1,y2, restore x3,y3,x4,y4. It can be shown that x3,y3,x4 and y4 uniquely exist and have integer values.
    Constraints
    ·|x1|,|y1|,|x2|,|y2|≤100
    ·(x1,y1) ≠ (x2,y2)
    ·All values in input are integers.

  • 输入
    Input is given from Standard Input in the following format:
    x1 y1 x2 y2

  • 输出
    Print x3,y3,x4 and y4 as integers, in this order.

  • 样例输入 Copy
    0 0 0 1

  • 样例输出 Copy
    -1 1 -1 0

  • 提示
    (0,0),(0,1),(−1,1),(−1,0) is the four vertices of a square in counter-clockwise order. Note that (x3,y3)=(1,1),(x4,y4)=(1,0) is not accepted, as the vertices are in clockwise order.

  • 题意分析 :就是有一个正方形,只知道它相邻的两个点,求<mark>逆时针</mark>的另两个点的坐标 。

  • 先说一下,我一开始的思路
    一开始想错了,这个实现就是A点在B左下可以,实现A点在B点的右上就会出错。当然可能能分类讨论,目前没分类

  • 思路:题意很简单,实现起来也简单,这个思路其实和那个差不多,我认为这是利用全等三角形之类的知识。就是1这个三角形与2这个三角形全等

  • xc就等于xb-(yb-ya);

  • 同样的 yc=yb+(xb-xa);

  • 知道c点的左边可以用B点和C点的坐标求出D点坐标;


代码:

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include <algorithm>
#define ll long long int
#define sc(a) scanf("%lld",&a)
const int mod=998244353;
using namespace std;
const int inf=1e9+7;
const int maxn=2e5+10;

ll n,m,sum,r,t,p,l;
ll a[maxn],b[maxn];
char str[maxn],s[maxn];

int main() {
	ll x2,y1,y2,x1,x3,x4,y3,y4;
	cin>>x1>>y1>>x2>>y2;
	x3=x2-(y2-y1);
	y3=y2+(x2-x1);
	x4=x3-(y3-y2);
	y4=y3+(x3-x2);
	printf("%lld %lld %lld %lld\n",x3,y3,x4,y4);
	return 0;
}

问题 M: Triangular Relationship

题目链接

  • You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same.

  • Constraints
    ·1≤N,K≤2×105
    ·N and K are integers.

  • 输入
    Input is given from Standard Input in the following format:
    N K

  • 输出
    Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.

  • 样例输入 Copy
    3 2

  • 样例输出 Copy
    9

  • 提示
    (1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.

  • 题意分析 :
    给定N和K。
    求三元组(a,b,c)的个数。
    三元组满足下面条件:
    a、b、c的值都是不大于N的正整数。
    a+b、b+c、a+c都是K的整数倍。

  • 思路分析
    根据数论同余的知识:
    a mod K + b mod K = K mod K.
    b mod K + c mod K = K mod K.
    a mod K + c mod K = K mod K.
    解得a=b=c=K/2 mod K(当K是偶数时有解)。或者a=b=c=K mod K。

  • 代码

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include <algorithm>
#define ll long long int
#define sc(a) scanf("%lld",&a)
const int mod=998244353;
using namespace std;
const int inf=1e9+7;
const int maxn=2e5+10;

ll n,m,sum,r,t,p,l;
ll a[maxn],b[maxn];
ll dp[maxn];
char str[maxn],s[maxn];

int main() {
	cin>>n>>m;
	t=n/m;
	p=n%m;
	sum=t*t*t;
	if(p>=m/2) t++;
	if(m%2==0)
	sum+=t*t*t;
	cout<<sum<<endl;
	return 0;
}