#include<iostream>
using namespace std;
int main()
{
for (int i = 2; i <= 1000; i++)
{
int sum = 0;
for (int j = 1; j < i; j++)
{
if (i % j == 0)
sum += j;
}
if (sum >= i)
cout << i << " ";
}
}
2017-3
#include<iostream>
#include<fstream>
#include<vector>
#include<unordered_map>
using namespace std;
int main()
{
vector<int>nums;
ifstream ifs("input3.txt");
int x;
while (ifs >> x)
nums.push_back(x);
int n = nums.size();
vector<unordered_map<int, int>>f(n);//f[i][j]表示以i结尾的且公差为j的最大子序列长度
int res = 0;
for (int i = 0; i < nums.size(); i++)
{
for (int j = 0; j < i; j++)
{
int d = nums[i] - nums[j];
f[i][d] = max(f[i][d], 2);
f[i][d] = max(f[j][d] + 1, f[i][d]);
res = max(res, f[i][d]);
}
}
cout << res;
}
2017.4
#include<iostream>
#include<fstream>
using namespace std;
const int N = 100010;
const int M = 2 * N;
int h[N], e[M], ne[M];
int idx = 0;
bool st[N];
int n;
void add(int a, int b)
{
e[idx] = b;
ne[idx] = h[a];
h[a] = idx++;
}
void dfs(int u)
{
st[u] = true;
for (int i = h[u]; i != -1; i = ne[i])
{
int j = e[i];
if (st[j]) continue;
dfs(j);
}
}
bool is_connect(int u)//判断是否连通,即判断去掉u,每个点是否被访问
{
if (u != 1)
dfs(1);
else
dfs(2);
for (int i = 1; i <= n; i++)
{
if (st[i] == false && i != u)
return false;
}
return true;
}
int main()
{
ifstream ifs("input4.txt");
ifs >> n;
int a, b;
int ans = 0;
for (int i = 1; i <= n; i++)
{
memset(h, -1, sizeof h);
memset(e, 0, sizeof e);
memset(ne, 0, sizeof ne);
memset(st, false, sizeof st);//每次遍历都要初始化所有数组,相当于新建一个图
idx = 0;
ifstream temp("input4.txt");
int t;
temp >> t;
while (temp >> a >> b)
{
if (a != i && b != i)//这一步相当于去掉点i,与i有关的边都不会添加
{
add(a, b);
add(b, a);
}
}
if (!is_connect(i))//有一个点不连通,则不是连通图,ans--
{
cout << i << endl;
ans--;
}
}
if (ans == 0)
cout << "not exist";
}