# Codeforces Round #346 (Div. 2) ABCDE

#include <iostream>
#include <string>

using namespace std;

int n, a, b;

int main()
{
while (cin >> n >> a >> b)
{
int ans;
ans = (a + b + n * 1000) % (n);
if (ans == 0) ans = n;
cout << ans << endl;
}
return 0;
}

B:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

vector <pair<int, string>> a[10010];

int n, m;
int main()
{
while (cin >> n >> m)
{

string tmp;
int num, val;
for (int i = 1;i <= n;i++)
{
cin >> tmp >> num >> val;
num--;
val = -val;
a[num].push_back(make_pair(val, tmp));
}

for (int i = 0;i < m;i++)
{

sort(a[i].begin(), a[i].end());
if (a[i].size() > 2 && a[i][1].first == a[i][2].first)
puts("?");
else
cout << a[i][0].second <<" "<< a[i][1].second << endl;
}
}
return 0;
}

C:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int n, m;
set<int> S;
vector<int> ans;

int main()
{
while (cin >> n >> m)
{
ans.clear();
S.clear();
set<int>::iterator pos;
vector<int>::iterator it;

int tmp;
for (int i = 1;i <= n;i++)
{
cin >> tmp;
S.insert(tmp);
}

tmp = 1;
while (m)
{
if (m < tmp) break;
if (S.count(tmp) == 0)
{
m -= tmp;
ans.push_back(tmp);
S.insert(tmp);
tmp++;
}
else
tmp++;
}
cout << ans.size() << endl;
for (it = ans.begin();it != ans.end();it++)
cout << *it << " ";
cout << endl;
}
return 0;
}

D:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int n;

struct
{
int x, y;
}a[1010];

int main()
{
while (scanf("%d", &n) != EOF)
{
memset(b, 0, sizeof(b));

for (int i = 0;i <= n;i++)
{
scanf("%d %d", &a[i].x, &a[i].y);
}

int ans = 0;
for (int i = 0;i < n;i++)
{
int t1 = i + 1;
int t2 = i + 2;
if (t2 == n + 1) t2 = 0;

if (a[i].x < a[i + 1].x && a[i].y == a[i + 1].y)//右
{
if (a[t1].x == a[t2].x && a[t1].y < a[t2].y)//↑
ans++;
}
else if (a[i].x > a[i + 1].x && a[i].y == a[i + 1].y)//左
{
if (a[t1].x == a[t2].x && a[t1].y > a[t2].y)//下
ans++;
}
else if (a[i].x == a[i + 1].x && a[i].y < a[i + 1].y)//上
{
if (a[t1].x > a[t2].x && a[t1].y == a[t2].y)//左
ans++;
}
else if (a[i].x == a[i + 1].x && a[i].y > a[i + 1].y)//下
{
if (a[t1].x < a[t2].x && a[t1].y == a[t2].y)//右
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}

E:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

const int MAXN = 200010;

vector<int> g[MAXN];

int n, m, nnode, nedge;
int vis[MAXN];

void dfs(int u)
{
vis[u] = 1;
nnode++;
for (int i = 0;i < g[u].size();i++)
{
int v = g[u][i];
nedge++;
if (!vis[v])
dfs(v);
}

}

int main()
{
while (scanf("%d %d", &n, &m) != EOF)
{
memset(vis, 0, sizeof vis);
for (int i = 0;i <= n;i++)
g[i].clear();
int u, v;
for (int i = 1;i <= m;i++)
{
scanf("%d %d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}

int ans = 0;
for (int i = 1;i <= n;i++)
{
if (!vis[i])
{
nnode = nedge = 0;
dfs(i);
if (nedge / 2 == nnode - 1)
ans++;
}
}

printf("%d\n", ans);
}
return 0;
}

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客