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)的更多相关文章

  1. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  2. Codeforces Round #279 (Div. 2) 题解集合

    终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...

  3. Codeforces Round #279 (Div. 2) vector

    A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. 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 ...

  5. 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 ...

  6. 【Codeforces Round#279 Div.2】B. Queue

    这题看别人的.就是那么诚实.http://www.cnblogs.com/zhyfzy/p/4117481.html B. Queue During the lunch break all n Ber ...

  7. Codeforces Round #279 (Div. 2)f

    树形最大上升子序列 这里面的上生子序列logn的地方能当模板使  good #include<iostream> #include<string.h> #include< ...

  8. Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理

    #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...

  9. Codeforces Round #279 (Div. 2) A. Team Olympiad 水题

    #include<stdio.h> #include<iostream> #include<memory.h> #include<math.h> usi ...

随机推荐

  1. oracle 建立主键与索引【转】

    此文转自:http://blog.sina.com.cn/s/blog_439f80c4010094n1.html 创建主键: alter table T add primary key (V) T是 ...

  2. Linux命令zip和unzip

    问题描述:        使用Linux中命令zip和unzip 问题解决: 命令名: zip  功能说明:压缩文件. 语 法:zip [-AcdDfFghjJKlLmoqrSTuvVwXyz$][- ...

  3. 使用Div+CSS布局设计网站的优点

    网页设计业界越来越关注DIV+CSS的标准化设计,大到各大门户网站,小到不计其数的个人网站,在Div+CSS标准化的影响下,网页设计人员已经把这一要求作为行业标准.那么什么是Div+CSS标准?Div ...

  4. MemSQL Start[c]UP 2.0 - Round 1

    A. Eevee http://codeforces.com/contest/452/problem/A 字符串水题 #include<cstdio> #include<cstrin ...

  5. PE文件结构详解(一)基本概念

    PE(Portable Execute) 文件是Windows下可执行文件的总称,常见的有DLL,EXE,OCX,SYS等,事实上,一个文件是否是PE文件与其扩展名无关,PE文件可以是任 何扩展名.那 ...

  6. uva 10330 最大流

    拆点  将节点 i 的容量拆成从 i 到 i+n 的边的容量 套用最大流模板 ac #include <cstdio> #include <cstdlib> #include ...

  7. Stateless Iterators

    As the name implies, a stateless iterator is an iterator that does not keep any state by itself. The ...

  8. VirtualBox 给虚拟机绑定IP

    在VirtualBox中,有时候打开虚拟机,会出现Waiting for 60 seconds more for network configuration这种情况,从而使得开机变得很慢. 通过以下操 ...

  9. Spring多资源文件properties的配置

    Spring简化了加载资源文件的配置,可以通过<context:property-placeholder去加载,这个元素的写法如下: <context:property-placehold ...

  10. 【Linux常识篇(1)】所谓的正向代理与反向代理

    正向代理的概念 正向代理,也就是传说中的代理,他的工作原理就像一个跳板,简单的说,我是一个用户,我访问不了某网站,但是我能访问一个代理服务器,这个代理服务器呢,他能访问那个我不能访问的网站,于是我先连 ...