CodeForces Round #279 (Div.2)
A:
题意:
有三个项目和n个学生,每个学生都擅长其中一个项目,现在要组成三个人的队伍,其中每个人恰好擅长其中一门,问能组成多少支队伍。
分析:
最多能组成的队伍的个数就是擅长项目里的最少学生。
#include <cstdio>
#include <vector>
#include <algorithm> using namespace std; int main(void)
{
int n, x;
vector<int> a[];
scanf("%d", &n);
for(int i = ; i <= n; ++i)
{
scanf("%d", &x);
a[x].push_back(i);
}
int aa = a[].size(), bb = a[].size(), cc = a[].size();
int ans = min(aa, bb);
ans = min(ans, cc);
printf("%d\n", ans);
for(int i = ; i < ans; ++i)
printf("%d %d %d\n", a[][i], a[][i], a[][i]); return ;
}
代码君
B:
题意:
有n个学生排成一队,他们有各自的学号(学号互不相同),现在知道每名学生前面那个人的学号ai和后面同学的学号bi,没有前驱或后继的补0,给出的顺序是任意的。要求顺序输出这些学号。
分析:
显然0是我们的突破点。如果n是偶数,从a中的那个0开始往后面推我们能得到排在偶数为的学号,从b中的0往前推,能得到奇数位置的学号。
n为奇数就略为棘手,不管从哪个0开始推,都只能得到偶数位置的学号。所以我们要另外分析奇数位置,发现:第一个学号是a、b中只出现一次且在a中的学号,找到这个头我们就可以往后面推了,当然如果找到的是b中只出现一次的那个尾也可以往前推。
代码比较挫,还是贴上来吧,毕竟是自己的孩子啊。
#include <cstdio> const int maxn = + ;
int left[maxn], right[maxn], cnt[maxn], vis[maxn];
int ans[maxn]; int main(void)
{
//freopen("Bin.txt", "r", stdin);
int n, a, b;
scanf("%d", &n);
for(int i = ; i < n; ++i)
{
scanf("%d%d", &a, &b);
right[a] = b;
left[b] = a;
cnt[a]++;
cnt[b]++;
}
if(n % == )
{
int t = ;
for(int i = ; i <= n; i += )
{
ans[i] = right[t];
t = right[t];
}
t = ;
for(int i = n-; i >= ; i -= )
{
ans[i] = left[t];
t = left[t];
}
}
else
{
int i, t = ;
for(i = ; i <= n; i += )
{
ans[i] = right[t];
vis[t] = ;
t = right[t];
}
for(i = ; i <= maxn; ++i)
if(cnt[i] == ) break;
t = i;
if(left[t] == )
{
for(int i = ; i <= n; i += )
{
ans[i] = t;
t = right[t];
}
}
else
{
for(int i = n; i >= ; i -= )
{
ans[i] = t;
t = left[t];
}
}
}
for(int i = ; i < n; ++i) printf("%d ", ans[i]);
printf("%d\n", ans[n]); return ;
}
代码君
又去翻了翻牛牛们的代码,发现他没有分奇偶,直接输出的,只弄明白大意。
#include <iostream> using namespace std; const int MAXN = ;
const int MAXA = ; int nex[MAXN];
int rb[MAXA], ra[MAXA];
int a[MAXN], b[MAXN]; int main()
{
//freopen("Bin.txt", "r", stdin);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int st = -, stid = -;
for (int i = ; i <= n; i++)
{
cin >> a[i] >> b[i];
ra[a[i]] = i;
rb[b[i]] = i;
if (a[i] == )
st = i;
}
for (int i = ; i <= n; i++)
if (rb[a[i]] == )
stid = a[i];
while (st != )
{
cout << stid << " ";
int nid = b[st];
st = ra[stid];
stid = nid;
}
cout << endl;
}
高冷的代码君
C: (高精度取模)
题意:
有一个大数s和两个int a、b,问是否能够将这个大数从中间分隔开,使得前面的数被a整除,后面的数被b整除,且不能有前导0。
分析:
从低位到高位计算低i位数模b的余数,然后从高位到低位计算高i位数模a的余数,如果有一个i的值满足前i位数被a整除后面的数被b整除且b不含前导0,这找到符合要求的分割,输出即可。
s.substr(pos, len)是求s的从pos开始,长度为len的子串。
#include <cstdio>
#include <string>
#include <iostream>
using namespace std; const int maxn = + ;
int mas[maxn]; int main()
{
//freopen("Cin.txt", "r", stdin);
ios::sync_with_stdio(false);
string s;
int a, b;
cin >> s >> a >> b;
int tmp = ;
mas[s.size()] = ;
for(int i = (int)s.size()-; i >= ; --i)
{
mas[i] = mas[i+] + tmp * (s[i] - '');
mas[i] = mas[i] % b;
tmp *= ;
tmp = tmp % b;
} tmp = ;
for(int i = ; i < (int)s.size()-; ++i)
{
tmp = tmp * + (s[i] - '');
tmp %= a;
if(tmp == && s[i+] != '') //²»ÄÜÓÐǰµ¼0
{
if(mas[i+] == )
{
cout << "YES\n";
cout << s.substr(, i+) << "\n";
cout << s.substr(i+, s.size()-i-) << "\n";
return ;
}
}
}
cout << "NO\n"; return ;
}
代码君
CodeForces Round #279 (Div.2)的更多相关文章
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #279 (Div. 2) 题解集合
终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...
- Codeforces Round #279 (Div. 2) vector
A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分
E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀
C. Hacking Cypher time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 【Codeforces Round#279 Div.2】B. Queue
这题看别人的.就是那么诚实.http://www.cnblogs.com/zhyfzy/p/4117481.html B. Queue During the lunch break all n Ber ...
- Codeforces Round #279 (Div. 2)f
树形最大上升子序列 这里面的上生子序列logn的地方能当模板使 good #include<iostream> #include<string.h> #include< ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- Codeforces Round #279 (Div. 2) A. Team Olympiad 水题
#include<stdio.h> #include<iostream> #include<memory.h> #include<math.h> usi ...
随机推荐
- 如何在cocos2dx lua的回调函数里面用self
回调里的self是另一个不同的东西了,通常是触发回调的对象,或_G或nil ,视情况而定 我的 print(self) 输出 userdata function MyClass:sayFromCall ...
- 传说中的Markov"不过如此”
因为看一篇题为 Passive Measurement of Interference in WiFi Network with Application in Misbehavior Detectio ...
- python 行转列
#encoding=utf- print '中国' #二维阵列变换 行转化成列,列转化成行 lista=[[,,],[,,],[,,],[,,]] #使用列表推导 listb=[[r[col] ])) ...
- 无root权限安装python
http://lujialong.com/?p=150 pipe 安装第三方包 http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip http://www.cn ...
- java多线程为什么要用while而不是if
对于java多线程的wait()方法,我们在jdk1.6的说明文档里可以看到这样一段话 从上面的截图,我们可以看出,在使用wait方法时,需要使用while循环来判断条件十分满足,而不是if,那么我们 ...
- uva 10859
刘书例题 树形dp #include <cstdio> #include <cstdlib> #include <cmath> #include <map& ...
- C#操作config文件
以下是app.config或web.config的定义,定义了一个参数,键为Isinit,值为false <?xml version="1.0"?> <confi ...
- 【redis】01Redis的介绍与安装部署
单元目标: 1.NoSQL介绍 2.Redis的介绍 3.Redis适用场合 4.Redis的安装与部署 5.Redis的数据类型 6.Redis的常用命令 7.Redis的高级应用 通过 ...
- mac上eclipse上配置hadoop
在mac上安装了eclipse之后,配置hadoop其实跟在linux上配置差不多,只是mac上得eclipse和界面和linux上得有点不同. 一:安装eclipse eclipse得安装比较简单, ...
- lintcode 中等题: Implement Trie
题目 Implement Trie Implement a trie with insert, search, and startsWith methods. 样例 注意 You may assu ...