codeforces#510 Div2
pre过了三题 后来A题被hack了 B题终测挂了 两题其实都是有一个小细节没有处理好 中间C还因为cinT了一次
唉本来打的还不错的 还是太菜了 继续加油吧
A-Benches
有n张椅子 原来第i张上有ai个人 现在来了m个人
求最大值的最大和最小的可能
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack> using namespace std; int n, m;
const int maxn = ;
int a[maxn]; int main()
{
while (cin >> n >> m) {
int maxpeo = -;
for (int i = ; i < n; i++) {
cin >> a[i];
maxpeo = max(maxpeo, a[i]);
} int maxk = maxpeo + m;
int sub = ;
for (int i = ; i < n; i++) {
sub += maxpeo - a[i];
}
int mink;
if(sub >= m){
mink = maxpeo;
}
else if ((m - sub) % n == ) {
mink = (m - sub) / n + maxpeo;
}
else {
mink = (m - sub) / n + + maxpeo;
} cout<<mink<<" "<<maxk<<endl;
}
}
B-Vitamins
有n瓶果汁,每瓶有一个价格 和 可能含有的维生素【最多只有ABC三种维生素】
现在想要用最少的钱集齐ABC
本来感觉是dp 写不出 所以先去写了C 后来发现其实贪心就能过
分类讨论一下 一种是 直接选三个维生素都有的里面价格最小的
一种是 选两个维生素加缺的里面价格最小的
一种是 选单个维生素价格最小的之和
存好含三种的果汁 两种的果汁 含A的果汁【不包括三种都有】含B的含C的
第一种可能只有一种情况
第二种可能 枚举 跑一遍
第三种可能也只有一种情况
比一下最小值
需要注意有可能有的数量是0
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack> #define inf 0x3f3f3f3f using namespace std; const int maxn = ;
int n;
struct node {
int c;
char vitamin[];
}juice[maxn];
node a[maxn], b[maxn], c[maxn], three[maxn], two[maxn]; bool cmp(node a, node b)
{
return a.c < b.c;
} int main()
{
while (scanf("%d", &n) != EOF) {
int cnta = , cntb = , cntc = , cntth = , cnttwo = ;
for (int i = ; i < n; i++) {
scanf("%d %s", &juice[i].c, juice[i].vitamin);
if (strlen(juice[i].vitamin) == ) {
three[cntth++] = juice[i];
}
else if (strlen(juice[i].vitamin) == ) {
two[cnttwo++] = juice[i];
for (int j = ; j < ; j++) {
if (juice[i].vitamin[j] == 'A') {
a[cnta++] = juice[i];
}
else if (juice[i].vitamin[j] == 'B') {
b[cntb++] = juice[i];
}
else {
c[cntc++] = juice[i];
}
}
}
else {
if (juice[i].vitamin[] == 'A') {
a[cnta++] = juice[i];
}
else if (juice[i].vitamin[] == 'B') {
b[cntb++] = juice[i];
}
else {
c[cntc++] = juice[i];
}
}
} if (cntth == && (cnta == || cntb == || cntc == )) {
printf("-1\n");
continue;
} sort(three, three + cntth, cmp);
sort(two, two + cnttwo, cmp);
sort(a, a + cnta, cmp);
sort(b, b + cntb, cmp);
sort(c, c + cntc, cmp); int ans;
if(cntth == ){
ans = inf;
}
else{
ans = three[].c;
}
for (int i = ; i < cnttwo; i++) {
if (strcmp(two[i].vitamin, "AB") == || strcmp(two[i].vitamin, "BA") == ) {
ans = min(ans, two[i].c + c[].c);
}
else if (strcmp(two[i].vitamin, "AC") == || strcmp(two[i].vitamin, "CA") == ) {
ans = min(ans, two[i].c + b[].c);
}
else {
ans = min(ans, two[i].c + a[].c);
}
}
if(cnta != && cntb != && cntc != ){
ans = min(ans, a[].c + b[].c + c[].c);
} printf("%d\n", ans);
}
}
C-Array Product
给一组数列 做n-1次操作
有两种操作 :第一种将ai和aj相乘结果赋给aj,ai删除
第二种 将ai位置删除【这种操作最多只能一次】
其实也是贪心
首先 所有的0都要合并 然后删去
负数 如果是奇数个的话 删去绝对值最小的那个
如果既有0又有奇数个负数 就把这个负数和0合并再删去
剩下的这些全部照常做第一种操作就好了
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack> #define inf 0x3f3f3f3f using namespace std; int n;
const int maxn = 2e5 + ;
int a[maxn];
bool vis[maxn]; int main()
{
//freopen("C:\\Users\\wyb\\Desktop\\tmpcode\\codeforces\\in.txt", "r", stdin);
//freopen("C:\\Users\\wyb\\Desktop\\tmpcode\\codeforces\\out.txt", "w", stdout);
while (scanf("%d", &n) != EOF) {
memset(vis, , sizeof(vis));
int cntmin = , lastzero = -, maxminpos, maxmin = -inf, cnt = ;
for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == ) {
if (lastzero == -) {
lastzero = i;
}
else {
printf("1 %d %d\n", lastzero, i);
//cout << "1 " << lastzero << " " << i << endl;
vis[lastzero] = false;
lastzero = i;
cnt++;
}
}
if (a[i] < ) {
cntmin++;
if (maxmin < a[i]) {
maxmin = a[i];
maxminpos = i;
}
}
}
if (cntmin % && lastzero != -) {
if(cnt == n - ){
continue;
}
cnt++;
printf("1 %d %d\n", maxminpos, lastzero);
//cout << "1 " << maxminpos << " " << lastzero << endl;
if(cnt == n - ){
continue;
}
cnt++;
printf("2 %d\n", lastzero);
//cout << "2 " << lastzero << endl;
vis[maxminpos] = vis[lastzero] = false;
}
else if (lastzero != -) {
if(cnt == n - ){
continue;
}
cnt++;
printf("2 %d\n", lastzero);
//cout << "2 " << lastzero << endl;
vis[lastzero] = false;
}
else if(cntmin % ){
if(cnt == n - ){
continue;
}
cnt++;
printf("2 %d\n", maxminpos);
//cout<<"2 "<<maxminpos<<endl;
vis[maxminpos] = false;
} int last = -;
for (int i = ; i <= n; i++) {
if (vis[i]) {
if (last == -) {
last = i;
}
else {
if(cnt == n - ){
break;
}
cnt++;
printf("1 %d %d\n", last, i);
//cout << "1 " << last << " " << i << endl;
last = i;
}
}
}
//cout<<endl;
}
}
codeforces#510 Div2的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces 510 E. Fox And Dinner
题目链接:http://codeforces.com/problemset/problem/510/E 乍一看和那啥魔术球问题有点神似啊/XD 其实是不一样的. 解决这道问题的关键在于发现若是相邻的两 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- Codeforces 510 A.Fox and Snake
题目链接:http://codeforces.com/contest/510/problem/A A. Fox And Snake time limit per test2 seconds memor ...
随机推荐
- Zookeeper 工作流
一旦ZooKeeper集合启动,它将等待客户端连接.客户端将连接到ZooKeeper集合中的一个节点.它可以是leader或follower节点.一旦客户端被连接,节点将向特定客户端分配会话ID并向该 ...
- CentOS 7 Minimal编译安装MySQL5.6
写在前面,编译安装MySQL的优势:平台无关.可设定参数按需安装.安装的MySQL目录独立(方便清楚).更好的平台耦合及运行性能(很多运维的观点):缺点:编译安装较慢. 一.撤换系统防火墙 注:Cen ...
- 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise
题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...
- python 模块之间相互引用
模块层级关系: ----: |->AA.py |->BB.py |->CC.py AA.py from BB import BB class AA: def sub(self, x) ...
- QListView的子项的ViewMode
QListView.setViewMode(ViewMode mode) enum QListView::ViewMode Constant Value DescriptionQListV ...
- PHPExcel正确读取excel表格时间单元格(转载)
error_reporting(E_ALL); date_default_timezone_set('Asia/shanghai'); /** PHPExcel_IOFactory */ requir ...
- windows环境下mongodb下载、安装和使用总结
一.首先安装mongodb 1.下载地址:http://dl.mongodb.org/dl/win32/x86_64 2.解压缩到自己想要安装的目录,比如d:\mongodb 3.创建文件夹d:\mo ...
- SQL Server 备份和还原数据库
备份: --完整备份 ) set @db_name = 'WSS_Content_Test'; ) set @db_location = 'D:\spbr0002\0000000B.bak'; --保 ...
- SVN目录权限设置
---恢复内容开始--- 如图,这里我建的项目库为myRepositories,其下边又有许多文件,现在要分别对每个文件进行svn权限配置. 配置 进入上面生成的文件夹conf下,进行配置.有以下几个 ...
- WAMP设置默认访问目录
打开httpd.conf 1.修改:DocumentRoot "F:/Project/Php" 2.修改 <Directory "F:/Project/Php&qu ...