Codeforces 850A - Five Dimensional Points(暴力)

本文解析了CodeForces上850A题目的解题思路及AC代码实现,通过判断五维空间中点之间的夹角来确定点的好坏,并给出了针对不同点数量的解决方案。

原题链接:http://codeforces.com/problemset/problem/850/A

 

题意:有n个五维空间内的点,如果其中三个点A,B,C,向量AB,AC的夹角不大于90°,则点A是“bad”的否则是“good”。题目让我们输出good的点。

思路:从2,3维空间超过5,7个点时不存在“good”的点,可以简单推知五维空间内,超过11个点时不存在“good”的点,那么点数小于11时暴力,大于11时输出0.

其实由于数据量小,直接暴力也是可行的。

 

AC代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<vector>
 5 using namespace std;
 6 const int MAXN=1005;
 7 struct Node{
 8     int a,b,c,d,e;
 9 }node[MAXN];
10 bool pend(Node A, Node B, Node C)
11 {
12     Node AB,AC;
13     AB.a=B.a-A.a;
14     AB.b=B.b-A.b;
15     AB.c=B.c-A.c;
16     AB.d=B.d-A.d;
17     AB.e=B.e-A.e;
18     AC.a=C.a-A.a;
19     AC.b=C.b-A.b;
20     AC.c=C.c-A.c;
21     AC.d=C.d-A.d;
22     AC.e=C.e-A.e;
23     if(AB.a*AC.a+AB.b*AC.b+AB.c*AC.c+AB.d*AC.d+AB.e*AC.e<=0) return 0;
24     return 1;
25 }
26 int main()
27 {
28     int n;
29     while(cin>>n)
30     {
31         
32         vector<int> res;
33         for(int i=0;i<n;i++){
34             scanf("%d %d %d %d %d", &node[i].a, &node[i].b, &node[i].c, &node[i].d ,&node[i].e);
35         }
36         if(n==1){
37             printf("%d\n%d\n", 1, 1);
38             continue;
39         }
40         else if(n==2){
41             printf("%d\n%d\n%d\n", 2, 1, 2);
42             continue;
43         }
44         else if(n>11){
45             printf("%d\n", 0);
46             continue;
47         }
48         bool flag;
49         for(int i=0;i<n;i++){
50             flag=0;
51             for(int j=0;j<n;j++){
52                 for(int k=j+1;k<n;k++){
53                     if(pend(node[i], node[j], node[k])){
54                         flag=1;
55                         j=n+1;
56                         break;
57                     }
58                 }
59             }
60             if(!flag) res.push_back(i);
61         }
62         int l=res.size();
63         printf("%d\n", l);
64         for(int i=0;i<l;i++)
65             printf("%d\n", res[i]+1);
66     }
67     return 0;
68 }

 

 

转载于:https://www.cnblogs.com/MasterSpark/p/7502616.html

### Codeforces Problem 976C Solution in Python For solving problem 976C on Codeforces using Python, efficiency becomes a critical factor due to strict time limits aimed at distinguishing between efficient and less efficient solutions[^1]. Given these constraints, it is advisable to focus on optimizing algorithms and choosing appropriate data structures. The provided code snippet offers insight into handling string manipulation problems efficiently by customizing comparison logic for sorting elements based on specific criteria[^2]. However, for addressing problem 976C specifically, which involves determining the winner ('A' or 'B') based on frequency counts within given inputs, one can adapt similar principles of optimization but tailored towards counting occurrences directly as shown below: ```python from collections import Counter def determine_winner(): for _ in range(int(input())): count_map = Counter(input().strip()) result = "A" if count_map['A'] > count_map['B'] else "B" print(result) determine_winner() ``` This approach leverages `Counter` from Python’s built-in `collections` module to quickly tally up instances of 'A' versus 'B'. By iterating over multiple test cases through a loop defined by user input, this method ensures that comparisons are made accurately while maintaining performance standards required under tight computational resources[^3]. To further enhance execution speed when working with Python, consider submitting codes via platforms like PyPy instead of traditional interpreters whenever possible since they offer better runtime efficiencies especially important during competitive programming contests where milliseconds matter significantly.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值