今天是水题集啊。。。。

A. Police Recruits
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print a single integer, the number of crimes which will go untreated.

Sample test(s)
input
3
-1 -1 1
output
2
input
8
1 -1 1 -1 -1 1 1 1
output
1
input
11
-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1
output
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 ;
 }

B. Prison Transfer
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print a single integer — the number of ways you can choose the c prisoners.

Sample test(s)
input
4 3 3
2 3 1 1
output
2
input
1 1 1
2
output
0
input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
output
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 }

C. Checkposts
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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 ≤ nu ≠ 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.

Output

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).

Sample test(s)
input
3
1 2 3
3
1 2
2 3
3 2
output
3 1
input
5
2 8 0 6 0
6
1 4
1 3
2 4
3 4
4 5
5 1
output
8 2
input
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
output
15 6
input
2
7 91
2
1 2
2 1
output
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 }

D. Match & Catch
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

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.

Input

The first line of input contains s1 and the second line contains s2 (1 ≤ |s1|, |s2| ≤ 5000). Both strings consist of lowercase Latin letters.

Output

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.

Sample test(s)
input
apple
pepperoni
output
2
input
lover
driver
output
1
input
bidhan
roy
output
-1
input
testsetses
teeptes
output
3

题意:给出两个串求出这两个串的最短公共序列,且这个公共序列在两个串中只出现一次。

sl:我是用字符串hash做的,但是这道题他卡hash常数,一直wa到142,无奈的看了下别人的代码为毛别人能过。

E. Police Patrol
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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++.

Output

Print a single integer, that means the minimum possible distance you need to cover to catch all the criminals.

Sample test(s)
input
3 6
1 2 3
output
4
input
5 5
-7 -6 -3 -1 1
output
16
input
1 369
0
output
0
input
11 2
-375 -108 1336 1453 1598 1892 2804 3732 4291 4588 4822
output
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)的更多相关文章

  1. Codeforces Round #244 (Div. 2)D (后缀自己主动机)

    Codeforces Round #244 (Div. 2)D (后缀自己主动机) (标号为0的节点一定是null节点,不管怎样都不能拿来用,切记切记,以后不能再错了) 这题用后缀自己主动机的话,对后 ...

  2. 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 ...

  3. Codeforces Round #244 (Div. 2) C. Checkposts (tarjan 强连通分量)

    题目:http://codeforces.com/problemset/problem/427/C 题意:给你n座城市,m条有向道路,然后有一个机制,你在某一个城市设置检查点,那么被设置的检查点受保护 ...

  4. Codeforces Round #244 (Div. 2) B. Prison Transfer

    题目是选出c个连续的囚犯,而且囚犯的级别不能大于t #include <iostream> using namespace std; int main(){ int n,t,c; cin ...

  5. Codeforces Round #244 (Div. 2) A. Police Recruits

    题目的意思就是找出未能及时处理的犯罪数, #include <iostream> using namespace std; int main(){ int n; cin >> ...

  6. Codeforces Round #244 (Div. 2)——Checkposts

    题目链接 题意: 给定n个点,每一个点有一个权值的有向图.如今须要选定一些点,使得这些点权值和最小.且满足:假设i能到达j且j能到达i,那么i.j能够仅仅选一个 分析: 强联通模板题 //使用时仅仅更 ...

  7. 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 ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. bzoj 1016: [JSOI2008]最小生成树计数【dfs+克鲁斯卡尔】

    有一个性质就是组成最小生成树总边权值的若干边权总是相等的 这意味着按边权排序后在权值相同的一段区间内的边能被选入最小生成树的条数是固定的 所以先随便求一个最小生成树,把每段的入选边数记录下来 然后对于 ...

  2. [Swift通天遁地]一、超级工具-(7)创建一个图文并茂的笔记本程序

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. Hadoop回收站及fs.trash参数详解

    前言: Linux系统里,个人觉得最大的不方便之一就是没有回收站的概念.rm -rf很容易造成极大的损失.而在Hadoop或者说HDFS里面,有trash(回收站)的概念,可以使得数据被误删以后,还可 ...

  4. python自动化测试学习笔记-9python的日志模块

    参考 logging模块,用来处理python中的日志: import logging logging.debug('debug')logging.info('info')logging.warnin ...

  5. ACM_校庆素数

    校庆素数 Time Limit: 2000/1000ms (Java/Others) Problem Description: 广财建校33年了,如今迎来了她的校庆. 小财最近想在研究素数,她突发奇想 ...

  6. HTML基础2——综合案例1——如何用iis配置网站

      1.打开iis 如果机子上面没有iis,可以先装一个,不同的系统可能安装步骤不一样,至于iis的安装方法,大家可以去百度找找.   2.准备网站源程序 既然要配置网站,肯定要先准备好网站源程序,网 ...

  7. mysqlbinlog(日志管理工具)

    mysqlbinlog用于处理二进制的日志文件,如果想要查看这些日志文件的文本内容,就需要使用mysqlbinlog工具. 1.mysqlbinlog命令的语法 shell > mysqlbin ...

  8. MySQL replace into 用法(insert into 的增强版)

    转 http://blog.csdn.net/risingsun001/article/details/38977797 MySQL replace into 用法(insert into 的增强版) ...

  9. IIS 相关配置

    IIS 和 VS 安装顺序 正常情况是先装IIS,后装VS:这样就不会发生错误了,因为asp.net就可以注册写入到IIS中.如果先装VS,再装IIS,这样就会导致"访问IIS元数据库失败& ...

  10. VMware workstation 14 CentOs 7.5.1804 虚拟机网卡设置为NAT模式并设置固定IP

    一.背景知识     虚拟机网络模式 无论是vmware workstation,virtual box,virtual pc等虚拟机软件,一般来说,虚拟机有三种网络模式: 1.桥接 2.NAT 3. ...