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 ...
随机推荐
- [原创] zabbix学习之旅七:如何远程操作被监控机器
虽然我们已经创建了一个报警系统,但在实际场景中,运维人员从得到报警到实际解决问题有一定的时差,若业务系统没有做高可用,那业务不得不中断,对于某些要求严格的企业级环境,这是不可容忍的,那有没有方法能让z ...
- maven学习心得整理
maven的学习心得 已经接触了maven项目有一段时间了,开始时仅仅会使用,在使用中发现了它的强大和方便,于是决心研究一下: 首先,普及一下maven参数: -D:传入属性参数 -P:使用POM中指 ...
- Hadoop以及其外围生态系统的安装参考
在研究Hadoop的过程中使用到的参考文档: 1.Hadoop2.2 参考文档 在CentOS上安装Hadoop 2.x 集群: http://cn.soulmachine.me/blog/201 ...
- 【BZOJ】【2819】NIM
这题……咋说捏,其实是一道披着博弈论外衣的树上操作问题…… 随便用dfs序或者树链剖分转成序列,然后查询路径上的所有点的NIM和(异或和)就行了,毕竟除了是在树上以外,就是裸的NIM问题. 树链剖分: ...
- 无废话网页重构系列——(6)HTML主干结构:站点(site)、页面(page)
本文作者:大象本文地址:http://www.cnblogs.com/daxiang/p/4653546.html 在分析和切出设计稿,以及部署项目目录文件后,开始写HTML Demo. 首先,弄出H ...
- css文件都写在一个里面还是每个页面都引用单独的css样式好?
因为网站比较小,外加网站页面有很多重复构件,决定采用“构件复用”搭建网页,但是遇到了一个问题.因为虽然有共同的css,但是每个页面或多或少都有独立的样式控制,到底是写在同一个css还是分离看上去清楚一 ...
- memcached+memadmin
一.安装apache yum install httpd 二.安装php yum install php* 三.apache配置 vi /etc/httpd/conf/httpd.conf 添加Add ...
- Mac OS X 快捷键(完整篇) 转载
转载自:http://www.nooidea.com/2011/01/mac-os-x-keyboard-shortcuts.html 快捷键是通过按下键盘上的组合键来调用 Mac OS X 功能的一 ...
- mac上eclipse上配置hadoop
在mac上安装了eclipse之后,配置hadoop其实跟在linux上配置差不多,只是mac上得eclipse和界面和linux上得有点不同. 一:安装eclipse eclipse得安装比较简单, ...
- hdu 4599 Dice 概率DP
思路: 1.求f[n];dp[i]表示i个连续相同时的期望 则 dp[0]=1+dp[1] dp[1]=1+(5dp[1]+dp[2])/6 …… dp[i]=1+(5dp[1 ...