http://codeforces.com/contest/864

第一次打cf的月赛……

A

题意:给你一个数列,问你能不能保证里面只有两种数且个数相等。2<=n<=100,1<=ai<=100。

水……没看完题就交了结果YES的时候还要输出这两种数是什么,然后就+1了……

#include <iostream>
#define maxn 105
using namespace std;
int n,a,t[maxn],c[maxn],d[maxn];
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a;
t[a]++;
}
int cnt=;
for(int i=;i<=;i++)
{
if(t[i])
{
c[++cnt]=t[i];
d[cnt]=i;
}
}
if(cnt!=)
cout<<"NO";
else if(c[]!=c[])
cout<<"NO";
else
cout<<"YES"<<endl<<d[]<<' '<<d[];
return ;
}

B

题意:给你一个只含字母的字符串,求仅由小写字母构成的最长子串。

从左到右扫一遍同时记录长度len,遇到大写字母就更新答案并把len归零就好了。一遍过。

#include <iostream>
#include <string>
#include <cctype>
#include <cstring>
using namespace std;
int n;
string s;
bool used[];
int main()
{
cin>>n>>s;
int len=,cnt=,ans=;
for(int i=;i<n;i++)
{
if(isupper(s[i]))
{
memset(used,false,);
len=;
cnt=;
}
else
{
len++;
if(!used[s[i]])
{
used[s[i]]=true;
cnt++;
ans=max(ans,cnt);
}
}
}
cout<<ans;
return ;
}

C

题意:一条直线道路,起点为0,终点为a,有一辆车在起点和终点来回开k次(来算一次,回算一次)。车的油箱有b汽油,每走1路程就耗1汽油。在路上f的位置有一个加油站,可以帮你把油箱加满。问要完成这k次来回最少需要加多少次油。

如果车现在停在加油站,并且油还够开到终点(或者起点)再回头开到加油站,那么显然不用加油。

干脆把加油站当作检查点,每次检查下还剩多少油,判断需不需要加油。k次以后输出结果。如果加了油也回不来加油站,那么输出-1。要注意特判第一回还有最后一回。

四遍才过……

#include <iostream>
using namespace std;
int a,b,f,k;
int main()
{
cin>>a>>b>>f>>k;
int ans=,pet=b-f;
if(pet<)
{
cout<<-;
return ;
}
bool ahead=true;
for(int i=;i<k;i++)
{
if(ahead)
{
if(pet-*(a-f)>=)
pet-=*(a-f);
else
pet=b-*(a-f),ans++;
}
else
{
if(pet-*f>=)
pet-=*f;
else
pet=b-*f,ans++;
}
ahead^=;
if(pet<)
{
cout<<-;
return ;
}
}
if(ahead)
{
if(pet-(a-f)<)
{
if(b-(a-f)>=)
ans++;
else
{
cout<<-;
return ;
}
}
}
else
{
if(pet-f<)
{
if(b-f>=)
ans++;
else
{
cout<<-;
return ;
}
}
}
cout<<ans;
return ;
}

D

题意:给你一个n项数列,里面的数字均在1~n范围内,问最少替换多少个数字才能变成一个1~n的排序,输出字典序最小的方案。

细节貌似有点多,还没做出来……

E

题意:有n个物品,每个物品价值为pi,拿起来要ti的时间,但是这个物品在时间大于等于di时就不能拿了。问怎样使拿到的物品价值之和最大。

容易看出这是道傻逼背包题,得f(i,j)=max{f(i-1,j), f(i-1,j-t[i])+p[i]} (j<d[i]且j>=t[i]),答案就是max{f(n,x) | 0<=x<=2000}。

当时还不懂怎么输出方案,比赛完了才想到每次转移记录一下,然后从答案开始逆过来找哪个物品被拿了。

然后交了上去,WA了。跑去看下别人的AC代码,发现别人都对物品按照di升序排序再选了。我也试了一发,交上去马上就A了。

之后才想明白,f(i,j)是按照1,2,...,i的顺序选择物品得到的价值最大值,如果不排序就会导致有些在后面但是d很小的物品选不到。

#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
int n;
struct item { int t, d, p, id; } a[];
bool cmp(const item& x, const item& y) { return x.d < y.d; }
int dp[][];
bool took[][];
int main()
{
ios::sync_with_stdio(false);
int ans = ;
cin >> n;
for (int i = ; i <= n; i++)
{
a[i].id = i;
cin >> a[i].t >> a[i].d >> a[i].p;
}
sort(a + , a + + n, cmp);
for (int i = ; i <= n; i++)
{
ans = ;
for (int j = ; j <= ; j++)
{
if (j < a[i].d && j >= a[i].t && dp[i - ][j - a[i].t] + a[i].p >= dp[i - ][j])
{
dp[i][j] = dp[i - ][j - a[i].t] + a[i].p;
took[i][j] = true;
}
else
dp[i][j] = dp[i - ][j]; if (dp[i][j] >= dp[i][ans])
ans = j;
}
}
cout << dp[n][ans] << endl;
stack<item> s;
int j = ans;
for (int i = n; i >= ; i--)
{
if (took[i][j])
{
s.push(a[i]);
j -= a[i].t;
}
}
cout << s.size() << endl;
while (!s.empty())
{
cout << s.top().id << ' ';
s.pop();
}
return ;
}

未完待+1s(可能)

Codeforces Round #436 (Div. 2)的更多相关文章

  1. Codeforces Round #436 (Div. 2)【A、B、C、D、E】

    Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...

  2. Codeforces Round #436 (Div. 2) C. Bus

    http://codeforces.com/contest/864/problem/C 题意: 坐标轴上有x = 0和 x = a两点,汽车从0到a之后掉头返回,从a到0之后又掉头驶向a...从0到a ...

  3. Codeforces Round #436 (Div. 2) E. Fire

    http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择 ...

  4. Codeforces Round #436 (Div. 2) D. Make a Permutation!

    http://codeforces.com/contest/864/problem/D 题意: 给出n和n个数(ai <= n),要求改变其中某些数,使得这n个数为1到n的一个排列,首先保证修改 ...

  5. Codeforces Round #436 (Div. 2) B. Polycarp and Letters

    http://codeforces.com/contest/864/problem/B 题意: 给出一个字符串,要求找到一个集合S,使得从S中选出的所有数,在这些数的位置上的字母全部为小写且是不同的字 ...

  6. Codeforces Round #436 (Div. 2)D. Make a Permutation! 模拟

    D. Make a Permutation! time limit per test: 2 seconds memory limit per test: 256 megabytes input: st ...

  7. Codeforces Round #436 (Div. 2)C. Bus 模拟

    C. Bus time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input out ...

  8. Codeforces Round #436 (Div. 2) A,B,D

    A. Fair Game 题目链接:http://codeforces.com/contest/864/problem/A 水题 #include<iostream> #include&l ...

  9. 【做题】Codeforces Round #436 (Div. 2) F. Cities Excursions——图论+dfs

    题意:给你一个有向图,多次询问从一个点到另一个点字典序最小的路径上第k个点. 考虑枚举每一个点作为汇点(记为i),计算出其他所有点到i的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张 ...

随机推荐

  1. MySQL数据库储存bit类型的值报错

    当我们储存bit类型的值时,不能直接写入数字 上图中的画圈部分就是bit类型,若是直接填入"1"或"0"等等就会报错,如下: 这时候,我们要看bit(M)的M值 ...

  2. Linux学习(四)单用户模式、救援模式、虚拟机克隆、linux互连(包括密匙登录)

    一.单用户模式 忘记root密码后,找回密码有两种方法: 单用户(grub没有加密的情况下可以使用) 救援模式 这一节我们先讲单用户模式   1.先重启(3种方法) reboot init 6 sho ...

  3. Problem Q

    Problem Description A factory produces products packed in square packets of the same height h and of ...

  4. 一款超好用轻量级JS框架——Zepto.js(上)

       前  言 絮叨絮叨 之前我们介绍过JQuery怎么自定义一个插件,但没有详细介绍过JQuery,那么今天呢....我们还是不说JQuery,哈哈哈哈 但是今天我们介绍一款和JQuery超级像的一 ...

  5. JS5模拟类

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. (二): 基于ZeroMQ的实时通讯平台

    基于ZeroMQ的实时通讯平台 上篇:C++分布式实时应用框架 (Cpp Distributed Real-time Application Framework)----(一):整体介绍 通讯平台作为 ...

  7. 原生js实现简单移动端轮播图

    最近项目不是很忙,自己就用原生js写了一个简单的移动端轮播图的小demo,可实现自动轮播和手势滑动轮播,然后就把它记录到个人博客里.还有很多不足的地方,希望多多指出,以便改进. 1.代码部分 分为四个 ...

  8. 学习C++ -> 构造函数与析构函数

    学习C++ -> 构造函数与析构函数 一.构造函数的介绍    1. 构造函数的作用        构造函数主要用来在创建对象时完成对对象属性的一些初始化等操作, 当创建对象时, 对象会自动调用 ...

  9. 六:Dubbo与Zookeeper、SpringMvc整合和使用

    DUBBO与ZOOKEEPER.SPRINGMVC整合和使用 互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架 ...

  10. 无限分级Repeater递归实现:读取一次数据库,使用LINQ2SQL技术,支持排序&amp;显示隐藏

    预览效果图: Selenium 数据库结构: id(int)    classname(string)   parentid(int) sort(int用于显示与排序) 1 家居 0 1 2 家电 0 ...