AtCoder Beginner Contest 108

本文解析了三道算法竞赛题目,包括寻找特定数对的数量、恢复被遗忘的坐标以完成正方形,以及寻找满足特定条件的整数三元组数量。通过代码示例详细解释了解决方案。

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

A - Pair

Time limit : 2sec / Memory limit : 1024MB

Score : 100 points

Problem Statement
Find the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.

Constraints
2≤K≤100
K is an integer.
Input
Input is given from Standard Input in the following format:

K
Output
Print the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).

Sample Input 1
3
Sample Output 1
2
Two pairs can be chosen: (2,1) and (2,3).

Sample Input 2
6
Sample Output 2
9
Sample Input 3
11
Sample Output 3
30
Sample Input 4
50
Sample Output 4
625

#include <stdio.h>
#include <math.h>
int main()
{
	int K, i, EvenNum, OddNum;
	EvenNum = OddNum = 0;
	scanf("%d",&K);
	for(i=1;i<=K;i++){
		if(i%2 == 0)
		    EvenNum++;
		else
		    OddNum++;
	}
	printf("%d\n",EvenNum * OddNum); 
	return 0;
}

B - Ruined Square

Time limit : 2sec / Memory limit : 1024MB

Score : 200 points

Problem Statement
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
Input is given from Standard Input in the following format:

x1 y1 x2 y2
Output
Print x3,y3,x4 and y4 as integers, in this order.

Sample Input 1
0 0 0 1
Sample Output 1
-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.

Sample Input 2
2 3 6 6
Sample Output 2
3 10 -1 7
Sample Input 3
31 -41 -59 26
Sample Output 3
-126 -64 -36 -131

#include <stdio.h>
int main()
{
	int x1, y1, x2, y2, x3, y3, x4, y4;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	x3 = x2 - (y2 - y1);
	y3 = y2 + (x2 - x1);
	x4 = x3 - (y3 - y2);
	y4 = y3 + (x3 - x2);
	printf("%d %d %d %d",x3,y3,x4,y4); 
	return 0;
}

C - Triangular Relationship

Time limit : 2sec / Memory limit : 1024MB

Score : 300 points

Problem Statement
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
Input is given from Standard Input in the following format:

N K
Output
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.

Sample Input 1
3 2
Sample Output 1
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.

Sample Input 2
5 3
Sample Output 2
1
Sample Input 3
31415 9265
Sample Output 3
27
Sample Input 4
35897 932
Sample Output 4
114191

#include <stdio.h>

int main(){
  
  int N,K;
  scanf("%d %d",&N,&K);
  
  long ans,x = N / K ,y = (N + K / 2) / K;
  
  if(K % 2 == 0){
    ans = x * x * x + y * y * y;
  }else{
    ans = x * x * x;
  }
  printf("%ld",ans);
    
  return 0;
}
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值