为帮助大家能在6月18日的比赛中有一个更好的成绩,我会将蓝桥杯官网上的历届决赛题目的四类语言题解都发出来。希望能对大家的成绩有所帮助。
今年的最大目标就是能为【一亿技术人】创造更高的价值。
资源限制
内存限制:256.0MB C/C++时间限制:1.0s Java时间限制:3.0s Python时间限制:5.0s
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1005;
int ans = 0 ;
int n;
map<int, int> mp;
void f(int a[],int va[]){
for(int i=1;i<=n;i++){
int cnt = 1;
mp.clear();
for(int j=i+1;j<=n;j++){
if(va[i] == va[j]){
if(a[i] == a[j]){
cnt++;
}
ans = max(ans , cnt);
continue ;
}
int dx = a[i] - a[j];
int dv = va[j] - va[i];
if(dv != 0){
int t = dx/dv;
if( dx%dv != 0 || t < 0)
continue ;
mp[t]++;
ans = max(ans , mp[t] + cnt);
}else{
if(dx == 0){
mp[0]++;
ans = max(ans , mp[0] + cnt);
}
}
}
}
//cout<<"1"<<endl;
return ;
}
int x[maxn],y[maxn],vx[maxn],vy[maxn];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int v;
char d;
cin>>x[i]>>y[i]>>v>>d;
if(d == 'R'){
vx[i] = v;
}
if(d == 'L'){
vx[i] = -v;
}
if(d == 'U'){
vy[i] = v;
}
if(d == 'D'){
vy[i] = -v;
}
}
f(x,vx);
f(y,vy);
cout<<ans<<endl;
return 0;
}
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static int X[], Y[], vx[], vy[];
static int mx = 0;
static int n;
static int m[];
static void f(int X[], int vx[]) {
for (int i = 1; i < n; i++) {
int cnt = 1;
ArrayList list=new ArrayList();
for (int j = i + 1; j <= n; j++) {
if (vx[i] == vx[j]) {
if (X[i] == X[j])
cnt++;
mx = Math.max(cnt, mx);
continue;
}
int dx = X[i] - X[j], dv = vx[j] - vx[i];
int t = dx / dv;
if (dx % dv != 0 || t < 0) {
continue;
}
m[t]++;
if(!list.contains(t)) {
list.add(t);
}
mx = Math.max(mx, m[t] + cnt);
}
for(int j=0;j<list.size();j++) {
m[(int) list.get(j)]=0;
}
}
}
public static void main(String[] args) {
{
m = new int[1000000];
Scanner in = new Scanner(System.in);
n = in.nextInt();
X = new int[1001];
Y = new int[1001];
vx = new int[1001];
vy = new int[1001];
for (int i = 1; i <= n; i++) {
int v;
char d;
X[i] = in.nextInt();
Y[i] = in.nextInt();
v = in.nextInt();
d = in.next().charAt(0);
if (d == 'R') {
vx[i] = v;
}
if (d == 'L') {
vx[i] = -v;
}
if (d == 'U') {
vy[i] = v;
}
if (d == 'D') {
vy[i] = -v;
}
}
f(X, vx);
f(Y, vy);
System.out.println(mx);
}
}
}