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. ADT eclipse打开时出现Error: Error parsing C:\Users\admin*\.android\devices.xml

    Error: Error parsing C:\Users\admin*\.android\devices.xml  在ADT eclipse打开项目的时候出现此提示,但是又不影响使用. 原因:之前安 ...

  2. java性能优化策略

    1. 尽量使用局部变量代替成员变量,循环中对成员变量.方法的调用不超过2次 2. ArrayList如果知道大小,初始化时应指明 3. HashMap的遍历,用Entry 4. 如果确定类不可继承尽量 ...

  3. Visual Studio 2013无法打开IIS Express Web的解决办法

    1. 首先参考了http://www.cr173.com/html/33412_1.html 2. 参考其最后,从微软官网下载安装WebMatrix,打开WebMatrix. 3. Visual St ...

  4. mysql 的数据文件

    mysql的数据文件 由于mysql的数据文件结构主要跟mysql的存储引擎相关,这里不做过多解释,具体查看各个引擎章节的内容 .首先上一段小辉老师的教程; 在MySQL 中每一个数据库都会在定义好( ...

  5. JS利用正则配合replace替换指定字符

    替换指定字符的方法有很多,在本文为大家详细介绍下,JS利用正则配合replace是如何做到的,喜欢的朋友可以参考下 定义和用法 replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一 ...

  6. 【转】Dancing Links题集

    转自:http://blog.csdn.net/shahdza/article/details/7986037 POJ3740 Easy Finding [精确覆盖基础题]HUST1017 Exact ...

  7. PHP对XML添加节点之appendChild()方法讲解

    问题如下:<b > <c>test</c> </b>我要在b节点里面添加一个子节点比如说加一个d节点,要实现成<b > <c>t ...

  8. java基础知识回顾之---java StringBuffer,Stringbuilder与String的区别

    public class StringBuilderTest { /** * StringBuffer和Stringbuilder :使用与内容可以被修改的字符串 * 与String的区别:Strin ...

  9. JAVASCRIPT的一些知识点梳理

    春节闲点,可以安心的梳理一下以前不是很清楚的东东.. 看的是以下几个URL: http://web.jobbole.com/82520/ http://blog.csdn.net/luoweifu/a ...

  10. [主席树]SPOJ DQUERY

    题目链接 题意:n个数 m个查询 查询的是[l, r]区间内不相同的数的个数 没有修改,因此静态的主席树就好了 将重复的元素建树即可 query的时候加起来,用区间长度(r-l+1)去减就是答案 (q ...