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 ...
随机推荐
- JSON-JObject
http://james.newtonking.com/json/help/index.html http://www.cnblogs.com/usharei/archive/2012/04/24/2 ...
- 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1、10、11、12、13因此共出现6次,但是对于后面问题他就没辙了。ACMer希望你们帮帮他,并把问题更加普遍化,可以很快的求出任意非负整数区间中1出现的次数。
// test20.cpp : 定义控制台应用程序的入口点. // include "stdafx.h" include include include include inclu ...
- 【BZOJ】【2179】FFT快速傅里叶
FFT 做的第二道用到FFT的……好吧其实还是模板题-_-b 百度上说好像分治也能做……不过像FFT这种敲模板的还是省事=.= /*********************************** ...
- source Insight注册码
source Insight vesion3.50.0058 注 册码SI3US-361500-17409
- java 几种常见的定时器
今天闲着没事就总结了一下在java中常用的几种定时器. 主要有3种java.util.Timer, ScheduledExecutorService和quartz 一.Timer 举个简单例子.每隔5 ...
- PKUSC 模拟赛 day1 下午总结
下午到了机房之后又困又饿,还要被强行摁着看英文题,简直差评 第一题是NOIP模拟赛的原题,随便模拟就好啦 本人模拟功力太渣不小心打错了个变量,居然调了40多分钟QAQ #include<cstd ...
- 500G JAVA视频网盘分享 (Jeecg社区)
http://blog.csdn.net/zhangdaiscott/article/details/18220411 csdn 排名400多名 500 G JAVA视频网盘分享(Jeecg社区 ...
- ServletRequest中getReader()和getInputStream()只能调用一次的解决办法
转载:http://blog.sina.com.cn/s/blog_870cd7b90101fg58.html 最近使用spring mvc做项目,数据格式是json,有一个功能是实现记录请求的参数, ...
- linux软中断与硬中断实现原理概述
linux软中断与硬中断实现原理概述. 1.软中断通过open_softirq注册一个软中断处理函数,即在软中断向量表softirq_vec数组中添加新的软中断处理action函数. 2.调用rais ...
- java nio管道
管道(Pipe) (本部分原文链接,作者:Jakob Jenkov,译者:黄忠,校对:丁一) Java NIO 管道是2个线程之间的单向数据连接.Pipe有一个source通道和一个sink通道.数据 ...