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

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces 510 E. Fox And Dinner

    题目链接:http://codeforces.com/problemset/problem/510/E 乍一看和那啥魔术球问题有点神似啊/XD 其实是不一样的. 解决这道问题的关键在于发现若是相邻的两 ...

  8. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  9. Codeforces 510 A.Fox and Snake

    题目链接:http://codeforces.com/contest/510/problem/A A. Fox And Snake time limit per test2 seconds memor ...

随机推荐

  1. android jni aotf 错误

    在jni中希望将字符串转成浮点型数据,使用了atof函数.出现错误: failed: Cannot load library: soinfo_relocate(linker.cpp:975): can ...

  2. unity3d绘画手册-------地形各个参数解释

    关于Unity3D是什么.我就不多做解释了.由于工作原因,该系列原创教程不定期更新.每月必然有更新.谢谢各位. Unity地形:: 新建地形: <ignore_js_op> 如图在菜单中新 ...

  3. 【Android实战】Android中处理崩溃异常

    public class MainActivity extends ActionBarActivity { public CrashApplication application; @Override ...

  4. VC++使用CSocket发送HTTP Request时需要注意发送数据的编码格式

    VS2010以及更高版本中新建的MFC项目字符集默认是Unicode,CString创建的字符串默认是Unicode. 使用CSocket时,若以CString组织需要发送的HTTP Head时,那么 ...

  5. asp.net mvc中用angularJs写的增删改查的demo。初学者,求指点。。

    直接给个代码下载链接.... http://pan.baidu.com/s/1FfVgq 本人刚刚学习angularJs,感觉双向数据绑定蛮爽的... 之前的代码存在点问题,已修复

  6. 同一种类型的两个对象赋值,用反射。再也不用点属性了。。。。(适用于ef)

    /// <summary> /// 给对象赋值的方法(不赋地址)(同一个类型),含过滤 /// </summary> /// <typeparam name=" ...

  7. VMware Host Agent服务不能正常启动

    VMware Host Agent服务不能正常启动 原因及解决方法 一直都在用VMWare Server 2.0,其他都还好,就是隔三差五的会有些小问题,比如VMware Host Agent服务不能 ...

  8. Linux 同步方法剖析--内核原子,自旋锁和相互排斥锁

    在学习 Linux® 的过程中,您或许接触过并发(concurrency).临界段(critical section)和锁定,可是怎样在内核中使用这些概念呢?本文讨论了 2.6 版内核中可用的锁定机制 ...

  9. Extjs不错的博客

    http://www.cnblogs.com/fangsui/category/372751.html http://www.cnblogs.com/WangJinYang/tag/EXT.NET/ ...

  10. Python 入门(四)List和Tuple类型

    创建list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可以用一个list表示: >>> ...