newcoder假日团队赛7 K-Game of Lines
链接:https://ac.nowcoder.com/acm/contest/997/K
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
Bessie can score a point in the game by picking two of the dots and drawing a straight line between them; however, she is not allowed to draw a line if she has already drawn another line that is parallel to that line. Bessie would like to know her chances of winning, so she has asked you to help find the maximum score she can obtain.
输入描述:
* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 describes lattice point i with two space-separated integers: Xi and Yi.
输出描述:
* Line 1: A single integer representing the maximal number of lines Bessie can draw, no two of which are parallel.
输入
4
-1 1
-2 0
0 0
1 1
输出
4
说明
Bessie can draw lines of the following four slopes: -1, 0, 1/3, and 1.
排个序再特判一下就出来了
1 #include <iostream>
2 #include <cstdio>
3
4 using namespace std;
5
6 typedef long long ll;
7 typedef char ch;
8 typedef double db;
9
10 void quick_sort(double q[],int l,int r)
11 {
12 if(l >= r) return;
13
14 int i=l-1,j=r+1;
15 double x=q[(l + r) >> 1];
16 while(i<j){
17 do i ++; while (q[i] < x);
18 do j --; while (q[j] > x);
19 if(i < j) swap(q[i] , q[j]);
20 }
21 quick_sort(q, l, j);
22 quick_sort(q, j + 1, r);
23 }
24
25 int main()
26 {
27 double x[300] = {0};
28 double y[300] = {0};
29 double a[50000] = {0};
30 int marker = 0;
31 int n, score = 0;
32
33 cin >> n;
34 for(int j = 0;j<n;j++)
35 {
36 scanf("%lf %lf",&x[j],&y[j]);
37 }
38 int L = 0;
39 for(int j = 0;j<n-1;j++)
40 {
41 for(int k = j+1;k<n;k++)
42 {
43 if(x[j] == x[k])
44 {
45 marker = 1;
46 }
47 else
48 {
49 a[L++] = double(y[k]-y[j])/(x[k]-x[j]);
50 }
51 }
52 }
53 //cout<<score<<endl;
54 quick_sort(a,0,L-1);
55
56 /*for(int j = 0;j<L;j++)
57 {
58 cout<<a[j]<<" ";
59 }*/
60 if(n > 2)
61 {
62 for(int j = 0;j<L-1 ;j++)
63 {
64 if(a[j]!=a[j+1]) score++;
65 }
66 score++;
67 }
68 if(marker)
69 {
70 score+=1;
71 // cout<<'!';
72 }
73 if(L == 0) score--;
74 cout<<score<<endl;
75 return 0;
76 }
之前因为有个暴力+1
所以当所有点在一条直线上且斜率不存在的时候会重复计数
这个故事告诉我们不能随便暴力+
错误代码(供自己反省)
1 #include <iostream>
2 #include <cstdlib>
3 using namespace std;
4
5 typedef long long ll;
6 typedef char ch;
7 typedef double db;
8
9 int cmp(const void * a, const void * b)
10 {
11 return((*(double*)a-*(double*)b>0)?1:-1);
12 }
13
14 double x[10005] = {0};
15 double y[10005] = {0};
16 double l[10005] = {0};
17
18 int main()
19 {
20 int marker = 0;
21 int n = 0 , score = 0;
22
23 cin >> n;
24 for(int i = 0;i<n;i++)
25 {
26 cin>>x[i]>>y[i];
27 }
28 int i = 0;
29 for(int j = 1;j<=n-1;j++)
30 {
31 for(int k = j+1;k<n;k++)
32 {
33 if(x[j] == x[k])
34 {
35 marker = 1;
36 }
37 else
38 {
39 l[i] = double(y[k]-y[j])/(x[k]-x[j]);
40 i++;
41 }
42 }
43 }
44 //cout<<score<<endl;
45 qsort(l,i,sizeof(l[0]),cmp);
46 /*
47 for(int j = 0;j<i;j++)
48 {
49 cout<<l[j]<<" ";
50 }
51 */
52 if(n > 2)
53 {
54 for(int j = 0;j<i-1 ;j++)
55 {
56 if(l[j]!=l[j+1])score+=1;
57 }
58 score++;
59 }
60 if(marker)
61 {
62 score+=1;
63 //cout<<'!';
64 }
65 cout<<score<<endl;
66 return 0;
67 }
newcoder假日团队赛7 K-Game of Lines的更多相关文章
- 牛客假日团队赛5 K 金币馅饼 (DP 基础题)
链接:https://ac.nowcoder.com/acm/contest/984/K 来源:牛客网 金币馅饼 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...
- 牛客假日团队赛1 A.蹄球锦标赛
链接: https://ac.nowcoder.com/acm/contest/918/A 题意: 为了准备即将到来的蹄球锦标赛,Farmer John正在训练他的N头奶牛(方便起见,编号为1-N,其 ...
- 牛客假日团队赛1 J.分组
链接: https://ac.nowcoder.com/acm/contest/918/J 题意: 在Farmer John最喜欢的节日里,他想要给他的朋友们赠送一些礼物.由于他并不擅长包装礼物,他想 ...
- 牛客假日团队赛1 I.接机
链接: https://ac.nowcoder.com/acm/contest/918/I 题意: 一场别开生面的牛吃草大会就要在Farmer John的农场举办了! 世界各地的奶牛将会到达当地的机场 ...
- 牛客假日团队赛1 G.Superbull
链接: https://ac.nowcoder.com/acm/contest/918/G 题意: Bessie and her friends are playing hoofball in the ...
- 牛客假日团队赛1 D.Promotion Counting
链接: https://ac.nowcoder.com/acm/contest/918/D 题意: Bessie the cow is helping Farmer John run the USA ...
- 牛客假日团队赛1B.便便传送门(一)
链接:https://ac.nowcoder.com/acm/contest/918/B 题意: Farmer John最讨厌的农活是运输牛粪.为了精简这个过程,他制造了一个伟大的发明:便便传送门!与 ...
- 牛客假日团队赛2 H.奶牛排序
链接: https://ac.nowcoder.com/acm/contest/924/H 题意: 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行动.因为脾 ...
- 牛客假日团队赛2 G.CountyFairEvents
链接: https://ac.nowcoder.com/acm/contest/924/G 题意: Farmer John has returned to the County Fair so he ...
- 牛客假日团队赛2 F.跳跃
链接: https://ac.nowcoder.com/acm/contest/924/F 题意: Farmer John为了满足奶牛对美的享受而安装了人工湖.矩形的人工湖分成M行N列(1 <= ...
随机推荐
- Ocelot和Consul 实现网关API 服务注册 负载均衡
Ocelot是一个用.NET Core实现并且开源的API网关,它功能强大,包括了:路由.请求聚合.服务发现.认证.鉴权.限流熔断.并内置了负载均衡器与Service Fabric.Butterfly ...
- 记一道有趣的交互题 noi.ac #2035歪比巴卜
记一道有趣的交互题 noi.ac #2035歪比巴卜 Problem Alice手上有两个\(\le n\)且不同的正整数\(x,y\),Bob手上有一个正整数\(z\),已经确认是\(x\)或\(y ...
- 你应该懂的AI大模型(一) 之 浅知大模型
1.AI 大模型的训练过程 AI 大模型的训练就如同让一名孩童从不会说话一步步培养成高级知识分子或者专家的过程. 第一步:收集数据,将海量的知识与文章收集起来作为学习资料教给这个孩子: 第二步:预处理 ...
- 16. MySQL 多版本并发控制
16. MySQL 多版本并发控制 @ 目录 16. MySQL 多版本并发控制 1. 什么是MVCC 2. 快照读与当前读 2.1 快照读 2.2 当前读 3. 复习 3.1 再谈隔离级别 3.2 ...
- java开发超级简单技巧
JAVA EE Java Platform,Enterprise Edition---java平台企业版 java SE Java Platform,Standard Edition---java平台 ...
- idea集成翻译插件
在读开源代码时,英文注释看起来比较吃力,于是安装一个翻译插件第一步:安装TranslateHelper插件 配置 IDEA -> Preferences -> Plugins ,安装Tra ...
- prettier继承
不支持extends prettier配置并不支持 extends 关键字,但是我们可以手动合并,比方说我们下载了一个配置包 @repo/config-prettier,我们可以如下继承到自己项目中 ...
- 【7】Tarjan学习笔记
前言 WFLS 暑假集训 Day 5 Day 6 Day 8 Day 9 Tarjan 是个巨佬,快来膜拜他 orz. 长文警告:本文一共 \(1092\) 行,请合理安排阅读时间. 强连通分量 强连 ...
- 遇见linux端运行qt程序报错, Could not find the Qt platform plugin “xcb“ in ““ This application failed to st
简介 .zshrc 里面进行设置 export QT_QPA_PLATFORM_PLUGIN_PATH=/mnt/hdd1/software/qt5_12_0/5.12.0/gcc_64/plugin ...
- ETL没有自动化数据集成平台,你的BI报表只会让你错失先机
随着现代企业的数据量和复杂性的不断增加,传统的商业智能(BI)报表系统虽然能够提供详尽的业务指标和洞察,但它们依赖于用户的主动查询和查看.这种被动式的数据分析模式存在几个显著的缺陷: 滞后性:用户需要 ...