Codeforces Round #244 (Div. 2)
今天是水题集啊。。。。
1 second
256 megabytes
standard input
standard output
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
The first line of input will contain an integer n (1 ≤ n ≤ 105), the number of events. The next line will contain n space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Print a single integer, the number of crimes which will go untreated.
3
-1 -1 1
2
8
1 -1 1 -1 -1 1 1 1
1
11
-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1
8
题意:求最后都几个人没有被抓。
sl: 简单模拟水题。敲完直接交的那一型。
1 /* *************
2 * by zhuyuqi *
3 * 2014/5/2 *
4 * codeforces *
5 * **************
6 */
7 #include<cstdio>
8 #include<cstring>
9 #include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int MAX = 1e5+;
const int MOD = ;
int a[MAX];
int main()
{
int n; int tot,sum;
while(scanf("%d",&n)==)
{
tot=sum=; int ans=;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]==-)
{
if(sum!=) sum--;
else ans++;
}
else
{
sum+=a[i];
}
}
printf("%d\n",ans);
}
return ;
}
1 second
256 megabytes
standard input
standard output
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
- The chosen c prisoners has to form a contiguous segment of prisoners.
- Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain nspace separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed109.
Print a single integer — the number of ways you can choose the c prisoners.
4 3 3
2 3 1 1
2
1 1 1
2
0
11 4 2
2 2 0 7 3 2 2 4 9 1 4
6
题意:选连续的m个数,要求每个所选的数大小不能超过t,求一共有多少种选法。
sl: 可以模拟做,我是用的RMQ sqarse-table裸过去的。
1 /* *************
2 * by zhuyuqi *
3 * 2014/5/2 *
4 * codeforces *
5 * **************
6 */
7 #include <iostream>
8 #include <math.h>
9 #include<cstdio>
#include<vector>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) (a<b?a:b)
using namespace std;
const int maxn = + ;
const int maxlog = ;
struct RMQ {
int d[maxn][maxlog];
void init(const vector<int>& A) {
int n = A.size();
for(int i = ; i < n; i++) d[i][] = A[i];
for(int j = ; (<<j) <= n; j++)
for(int i = ; i + (<<j) - < n; i++)
d[i][j] = max(d[i][j-], d[i + (<<(j-))][j-]);
}
int query(int L, int R) {
int k = ;
while((<<(k+)) <= R-L+) k++;
return max(d[L][k], d[R-(<<k)+][k]);
}
};
int a[maxn];
RMQ rmq;
int main()
{
int n,t,c; vector<int> count; int ans=;
scanf("%d%d%d",&n,&t,&c);
for(int i=;i<=n;i++) scanf("%d",&a[i]),count.push_back(a[i]);
rmq.init(count);
for(int i=;i<=n-c;i++)
{
// printf("%d\n",rmq.query(i,i+c-1));
if(rmq.query(i,i+c-)<=t) ans++;
}
printf("%d\n",ans);
return ;
48 }
2 seconds
256 megabytes
standard input
standard output
Your city has n junctions. There are m one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction i can protect junction j if either i = j or the police patrol car can go to j from i and then come back to i.
Building checkposts costs some money. As some areas of the city are more expensive than others, building checkpost at some junctions might cost more money than other junctions.
You have to determine the minimum possible money needed to ensure the security of all the junctions. Also you have to find the number of ways to ensure the security in minimum price and in addition in minimum number of checkposts. Two ways are different if any of the junctions contains a checkpost in one of them and do not contain in the other.
In the first line, you will be given an integer n, number of junctions (1 ≤ n ≤ 105). In the next line, n space-separated integers will be given. The ithinteger is the cost of building checkpost at the ith junction (costs will be non-negative and will not exceed 109).
The next line will contain an integer m (0 ≤ m ≤ 3·105). And each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; u ≠ v). A pair ui, vi means, that there is a one-way road which goes from ui to vi. There will not be more than one road between two nodes in the same direction.
Print two integers separated by spaces. The first one is the minimum possible money needed to ensure the security of all the junctions. And the second one is the number of ways you can ensure the security modulo 1000000007 (109 + 7).
3
1 2 3
3
1 2
2 3
3 2
3 1
5
2 8 0 6 0
6
1 4
1 3
2 4
3 4
4 5
5 1
8 2
10
1 3 2 2 1 3 1 4 10 10
12
1 2
2 3
3 1
3 4
4 5
5 6
5 7
6 4
7 3
8 9
9 10
10 9
15 6
2
7 91
2
1 2
2 1
7 1
题意:要求修建一些警察局,来保护一些节点 在i处的警察局能保护j 必须是这两个点相互可达。每个节点修建警察局都有相应的花费。求出
修建最少的警察局花费的最少金额,以及修建方案的个数。
sl 很裸的双联通缩点,缩完点之后求出每个连通分量中的最少金额加起来就是总的最少金额。 统计一下每个连通分量中最少金额为x的有几个点
然后乘法原理计数就行。
1 /* *************
2 * by zhuyuqi *
3 * 2014/5/2 *
4 * codeforces *
5 * **************
6 */
7 #include<cstdio>
8 #include<cstring>
9 #include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int MAX = 1e5+;
const int MOD = 1e9+;
vector<int> G[MAX],G2[MAX];
vector<int> S;
int vis[MAX],sccno[MAX],scc_cnt;
int cost[MAX];
int Min[MAX],num[MAX];
void add_edge(int from,int to)
{
G[from].push_back(to);
G2[to].push_back(from);
}
void dfs(int u)
{
if(vis[u]) return ;
vis[u]=;
for(int i=;i<G[u].size();i++) dfs(G[u][i]);
S.push_back(u);
}
void rdfs(itn u)
{
if(sccno[u]) return;
sccno[u]=scc_cnt;
for(int i=;i<G2[u].size();i++) dfs2(G2[u][i]);
}
int main()
{
int n,m; int a,b;
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&cost[i]);
scanf("%d",&m);
for(int i=;i<m;i++)
{
scanf("%d %d",&a,&b); a--; b--;
add_edge(a,b);
}
S.clear(); scc_cnt=;
memset(sccno,,sizeof(sccno));
memset(vis,,sizeof(vis));
for(int i=;i<n;i++) dfs(i);
for(int i=n-;i>=;i--)
{
if(!sccno[S[i]]) {scc_cnt++; rdfs(S[i]);}
}
for(int i=;i<n;i++) Min[i]=inf;
memset(num,,sizeof(num));
for(int i=;i<n;i++)
{
Min[sccno[i]]=min(cost[i],Min[sccno[i]]);
}
for(int i=;i<n;i++)
{
if(Min[sccno[i]]==cost[i]) num[sccno[i]]++;
}
int ans=,ret=;
for(int i=;i<scc_cnt;i++)
{
ans+=Min[i];
ret=(ret*num[i])%MOD;
}
printf("%d %d\n",ans,ret);
return ;
78 }
1 second
512 megabytes
standard input
standard output
Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings s1 and s2 from two different frequencies as signals. They are suspecting that these two strings are from two different criminals and they are planning to do some evil task.
Now they are trying to find a common substring of minimum length between these two strings. The substring must occur only once in the first string, and also it must occur only once in the second string.
Given two strings s1 and s2 consist of lowercase Latin letters, find the smallest (by length) common substring p of both s1 and s2, where p is a unique substring in s1 and also in s2. See notes for formal definition of substring and uniqueness.
The first line of input contains s1 and the second line contains s2 (1 ≤ |s1|, |s2| ≤ 5000). Both strings consist of lowercase Latin letters.
Print the length of the smallest common unique substring of s1 and s2. If there are no common unique substrings of s1 and s2 print -1.
apple
pepperoni
2
lover
driver
1
bidhan
roy
-1
testsetses
teeptes
3
题意:给出两个串求出这两个串的最短公共序列,且这个公共序列在两个串中只出现一次。
sl:我是用字符串hash做的,但是这道题他卡hash常数,一直wa到142,无奈的看了下别人的代码为毛别人能过。
1 second
256 megabytes
standard input
standard output
Imagine that your city is an infinite 2D plane with Cartesian coordinate system. The only crime-affected road of your city is the x-axis. Currently, there are n criminals along the road. No police station has been built on this road yet, so the mayor wants to build one.
As you are going to be in charge of this new police station, the mayor has asked you to choose a suitable position (some integer point) for building it. You should choose the best position for the police station, so that you could minimize the total time of your criminal catching mission. Your mission of catching the criminals will operate only from this station.
The new station will have only one patrol car. You will go to the criminals by this car, carry them on the car, bring them back to the police station and put them in prison. The patrol car can carry at most m criminals at a time. Note that, the criminals don't know about your mission. So, they will stay where they are instead of running away.
Your task is to find the position for the police station, so that total distance you need to cover to catch all the criminals will be minimum possible. Note that, you also can built the police station on the positions where one or more criminals already exist. In such a case all these criminals are arrested instantly.
The first line of the input will have two integers n (1 ≤ n ≤ 106) and m (1 ≤ m ≤ 106) separated by spaces. The next line will contain n integers separated by spaces. The ith integer is the position of the ith criminal on the x-axis. Absolute value of positions will not exceed 109. If a criminal has position x, he/she is located in the point (x, 0) of the plane.
The positions of the criminals will be given in non-decreasing order. Note, that there can be more than one criminal standing at some point of the plane.
Note: since the size of the input/output could be very large, don't use slow input/output techniques in your language. For example, do not use input/output streams (cin, cout) in C++.
Print a single integer, that means the minimum possible distance you need to cover to catch all the criminals.
3 6
1 2 3
4
5 5
-7 -6 -3 -1 1
16
1 369
0
0
11 2
-375 -108 1336 1453 1598 1892 2804 3732 4291 4588 4822
18716
题意:求出一个警察局的修建位置,求出这个点到其他的点来回做多少路。
sl:直接模拟就行,把警察局建在中间就行,求前缀和模拟也行。
1 /* *************
2 * by zhuyuqi *
3 * 2014/5/3 *
4 * codeforces *
5 * **************
6 */
7 #include<cstdio>
8 #include<cstring>
9 #include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int MAX = 1e6+;
const int MOD = ;
int n,m;
int x[MAX];
int main()
{
int n,m; int pos,L,R,md; int begin;
LL ans;
while(scanf("%d %d",&n,&m)==)
{
for(int i=;i<=n;i++) scanf("%d",&x[i]);
sort(x+,x+n+);
if(n&) pos=n/+,md=x[n/+];
else pos=n/,md=x[n/];
L=; begin=L; ans=; R=n;
while(begin<pos)
{
while(begin-L<m&&begin<pos) begin++;
ans+=(md-x[L])*;
L=begin;
}
begin=R;
while(begin>pos)
{
while(R-begin<m&&begin>pos) begin--;
ans+=(x[R]-md)*;
R=begin;
}
printf("%I64d\n",ans);
}
return ;
}
Codeforces Round #244 (Div. 2)的更多相关文章
- Codeforces Round #244 (Div. 2)D (后缀自己主动机)
Codeforces Round #244 (Div. 2)D (后缀自己主动机) (标号为0的节点一定是null节点,不管怎样都不能拿来用,切记切记,以后不能再错了) 这题用后缀自己主动机的话,对后 ...
- Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- Codeforces Round #244 (Div. 2) C. Checkposts (tarjan 强连通分量)
题目:http://codeforces.com/problemset/problem/427/C 题意:给你n座城市,m条有向道路,然后有一个机制,你在某一个城市设置检查点,那么被设置的检查点受保护 ...
- Codeforces Round #244 (Div. 2) B. Prison Transfer
题目是选出c个连续的囚犯,而且囚犯的级别不能大于t #include <iostream> using namespace std; int main(){ int n,t,c; cin ...
- Codeforces Round #244 (Div. 2) A. Police Recruits
题目的意思就是找出未能及时处理的犯罪数, #include <iostream> using namespace std; int main(){ int n; cin >> ...
- Codeforces Round #244 (Div. 2)——Checkposts
题目链接 题意: 给定n个点,每一个点有一个权值的有向图.如今须要选定一些点,使得这些点权值和最小.且满足:假设i能到达j且j能到达i,那么i.j能够仅仅选一个 分析: 强联通模板题 //使用时仅仅更 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- bzoj 1426: 收集邮票【期望dp】
我太菜了,看的hzwer的blog才懂 大概是设f[i]表示已经拥有了i张邮票后期望还要买的邮票数,这个转移比较简单是f[i]=f[i]*(i/n)+f[i+1]*((n-i)/n)+1 然后设g[i ...
- StackOverflow 创始人关于如何高效编程的清单
这是 StackOverflow 联合创始人 Jeff Atwood 注释的十戒.程序员普遍有很强的自尊心,都应该看看本文,打印下来时刻提醒自己. “无我编程”发生在开发阶段,表现为技术团队经常通过同 ...
- CentOS环境下下调整home和根分区大小
项目建设方给提供了3台CentOS的服务器,连接进去之后发现磁盘空间很大,但是都放在了home目录下,所以需要调整一下. 1.查看磁盘使用情况 [root@CentOS ~]# df -h Files ...
- HTML DOM getElementById() 方法
定义和用法 getElementById() 方法可返回对拥有指定 ID 的第一个对象的引用. 语法 document.getElementById(id) 说明 HTML DOM 定义了多种查找元素 ...
- C#模拟百度登录并到指定网站评论回帖(三)
上次说到怎么获取BAIDUID,这个相信很多人都能够拿到就不多说了,今天一连说两个,获取token和raskey 2.利用以上获得的cookie直接访问页面 https://passport.baid ...
- php循环结构
1.while循环 先判断条件,如果条件成立则执行循环的代码 嵌套循环,需要先把嵌套在内的循环执行完毕再执行外面的循环 While(条件语句){......} //如果()条件成立,执行{}里面的语句 ...
- [ HAOI 2008 ] 圆上的整点
\(\\\) Description 给出一个整数 \(r\) ,求圆 \(x^2+y^2=r^2\) 上的整点数. \(r\le 2\times 10^9\) \(\\\) Solution 神题. ...
- Python代码搜索并下载酷狗音乐
运行环境: Python3.5+Pycharm 实例代码: import requests,re keyword = input("请输入想要听的歌曲:") url = " ...
- DatePickerDialog日期对话框以及回调函数的用法
DatePickerDialog类的实例化需要用到回调接口,如下定义: android.app.DatePickerDialog.DatePickerDialog(Context context, O ...
- R语言曲线拟合函数(绘图)
曲线拟合:(线性回归方法:lm) 1.x排序 2.求线性回归方程并赋予一个新变量 z=lm(y~x+I(x^2)+...) 3.plot(x,y) #做y对x的散点图 4.lines(x ...