A - Toy Cars

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.

There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car:

  •  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix.
  • 0: if no car turned over during the collision.
  • 1: if only the i-th car turned over during the collision.
  • 2: if only the j-th car turned over during the collision.
  • 3: if both cars turned over during the collision.

Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?

 

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of cars.

Each of the next n lines contains n space-separated integers that determine matrix A.

It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix.

It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.

 

Output

Print the number of good cars and in the next line print their space-separated indices in the increasing order.

Sample Input

 

Input
3
-1 0 0
0 -1 1
0 2 -1
Output
2
1 3
Input
4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1
Output
0

 

题意:

共有n辆车互相碰撞,表现为一个n*n的矩阵,矩阵的对角线为-1表示自己对自己。行和列分别表示为i-th和j-th,当(i-th,j-th)为1时表示i-th翻车,2时表示j-th翻车,3

时表示两车全部翻车。0表示没有车翻车。只要没有翻过的车就是好车。

 

思路:

对于每行扫描,当出现1/3时,就说明翻过车。

 

附AC代码:

 1 #include<iostream>
 2 #include<vector>
 3 using namespace std;
 4 
 5 int a[110][110];
 6 vector<int> v; //用一个vector容器来储存好车
 7 
 8 int main(){
 9     int n;
10     cin>>n;
11     for(int i=1;i<=n;i++){
12         int flag=1;
13         for(int j=1;j<=n;j++){
14             cin>>a[i][j];
15             if(a[i][j]==1||a[i][j]==3){
16                 flag=0;
17             }    
18         }
19         if(flag==1)
20             v.push_back(i);
21     }
22     int s=v.size();
23     cout<<s<<endl;
24     if(s!=0){
25         for(int i=0;i<s-1;i++){
26         cout<<v[i]<<" ";
27     }
28     cout<<v[s-1]<<endl;
29     }
30     
31     return 0;
32 } 

 

转载于:https://www.cnblogs.com/Kiven5197/p/5709782.html

AI-PPT 一键生成 PPT:用户输入主题关键词,AI-PPT 可快速生成完整 PPT,涵盖标题、正文、段落结构等,还支持对话式生成,用户可在 AI 交互窗口边查看边修改。 文档导入转 PPT:支持导入 Word、Excel、PDF 等多种格式文档,自动解析文档结构,将其转换为结构清晰、排版规范的 PPT,有保持原文和智能优化两种模式。 AI-PPT 对话 实时问答:用户上传 PPT 或 PPTX 文件后,可针对演示内容进行提问,AI 实时提供解答,帮助用户快速理解内容。 多角度内容分析:对 PPT 内容进行多角度分析,提供全面视野,帮助用户更好地把握内容结构和重点。 多语言对话支持:支持多语言对话,打破语言障碍,方便不同语言背景的用户使用。 AI - 绘图 文生图:用户输入文字描述,即可生成符合语义的不同风格图像,如油画、水彩、中国画等,支持中英文双语输入。 图生图:用户上传图片并输入描述,AI - 绘图能够根据参考图和描述生成新的风格化图像,适用于需要特定风格或元素的创作需求。 图像编辑:提供如 AI 超清、AI 扩图、AI 无痕消除等功能,用户可以上传图片进行细节修改和优化,提升图片质量。 AI - 文稿 文案生成:能够根据用户需求生成多种类型的文章,如市场营销文案、技术文档、内部沟通内容等,提升文案质量和创作效率。 文章润色:对已有文章进行改善和优化,包括语言表达、逻辑连贯性、内容流畅度等方面,使文章更符合用户期望和风格。 文章续写:AI 技术理解文本语境,为用户提供新的想法、补充资料或更深层次的见解,帮助用户丰富文档内容。 AI - 医生 智能健康咨询:包括症状自查,用户输入不适症状,AI 结合病史等信息提供疾病可能性分析与初步建议;用药指导,支持查询药品适应症、禁忌症等,并预警潜在冲突;中医辨证,提供体质辨识与调理建议。 医学报告解读:用户上传体检报告
03-18
### 支持向量机 (SVM) 的玩具示例和数据集 支持向量机是一种强大的监督学习方法,广泛应用于分类和回归分析。为了帮助理解 SVM 的工作原理及其应用效果,可以利用一些经典的玩具数据集或可视化工具来探索其性能。 #### 常见的 SVM 玩具数据集 以下是几个常用的玩具数据集以及如何通过 Python 和 `scikit-learn` 库实现简单的 SVM 示例: 1. **Iris 数据集** Iris 数据集是一个经典的小型数据集,包含三类鸢尾花的数据样本,每类有 50 个实例,总共有 150 条记录。该数据集非常适合用于二元或多类别分类任务。 ```python from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.svm import SVC # 加载 Iris 数据集 iris = datasets.load_iris() X, y = iris.data, iris.target # 划分训练集和测试集 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) # 创建并训练 SVM 模型 clf = SVC(kernel='linear', C=1.0, random_state=42) clf.fit(X_train, y_train) # 测试模型准确性 accuracy = clf.score(X_test, y_test) print(f"Accuracy on the test set: {accuracy:.2f}") ``` 2. **Moons 数据集** Moons 数据集由两个互锁的新月形分布组成,适合用来展示非线性决策边界的效果。 ```python from sklearn.datasets import make_moons import matplotlib.pyplot as plt # 生成 Moons 数据集 X, y = make_moons(n_samples=100, noise=0.1, random_state=42) # 可视化数据点 plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired, s=20) plt.title('Moons Dataset') plt.show() # 使用 RBF 核函数训练 SVM clf = SVC(kernel='rbf', gamma='auto', C=1.0, random_state=42) clf.fit(X, y) # 绘制决策边界 xx, yy = np.meshgrid(np.linspace(-2, 3, 500), np.linspace(-2, 2, 500)) Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()]) Z = Z.reshape(xx.shape) plt.contourf(xx, yy, Z > 0, alpha=0.8, cmap=plt.cm.Paired) plt.scatter(X[:, 0], X[:, 1], c=y, edgecolors='k', cmap=plt.cm.Paired, s=20) plt.title('Decision Boundary with RBF Kernel') plt.show() ``` 3. **Circles 数据集** Circles 数据集由两组同心圆构成,同样适用于研究非线性核函数的表现。 ```python from sklearn.datasets import make_circles # 生成 Circles 数据集 X, y = make_circles(n_samples=100, factor=.3, noise=0.1, random_state=42) # 可视化数据点 plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired, s=20) plt.title('Circles Dataset') plt.show() # 训练带有 RBF 核函数的 SVM clf = SVC(kernel='rbf', gamma='auto', C=1.0, random_state=42) clf.fit(X, y) # 绘制决策边界 xx, yy = np.meshgrid(np.linspace(-1.5, 1.5, 500), np.linspace(-1.5, 1.5, 500)) Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()]) Z = Z.reshape(xx.shape) plt.contourf(xx, yy, Z > 0, alpha=0.8, cmap=plt.cm.Paired) plt.scatter(X[:, 0], X[:, 1], c=y, edgecolors='k', cmap=plt.cm.Paired, s=20) plt.title('Decision Boundary with RBF Kernel') plt.show() ``` 以上代码展示了如何加载常见数据集、构建 SVM 模型,并绘制相应的决策边界[^1]。 #### 关于 SVM 复杂度的优势 值得注意的是,SVM 的预测效率主要取决于支持向量的数量而非特征空间的维度,这使得它在高维稀疏场景下表现尤为突出[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值