2017.08.25 阿里笔试题:自由之路

来源:互联网 发布:调查问卷数据分析方法 编辑:程序博客网 时间:2024/05/16 09:15

真的没想到我能做出来且全部通过,超级开心啊啊啊啊啊。


找到规律就很简单,我一下就想到了01矩阵,矩阵排列是有规律的,在4*4、5*5矩阵中找规律,其实组队个数就等于每两两人相识的总数,这样一想就很简单了。每输入一行就从当前人所在列开始统计1的个数。


 #include <iostream>
#include <vector>

using namespace std;

int main() {
int n;
cin >> n;
int m;
cin >> m;
vector<int> count;
int temp;
int temp2 = 0;
char dou;
count.clear();
for (int j=0;j<n;j++)
{
count.push_back(0);
int k =j;
while(k--)
{
cin >>temp;
cin >> dou; 
}
for (int i=j;i<m;i++)
{
cin >>temp;
if(i!=m-1) cin >> dou; 
if (temp ==1)
{
count[j]++;
}
}
count[j]--;
temp2+=count[j];
}

cout << n-temp2;

return 0;
}

原创粉丝点击