热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CodeforcesRound#244(Div.2)

今天是水题集啊。。。。A.PoliceRecruitstimelimitpertest1secondmemorylimitpertest256megabytesinputsta

今天是水题集啊。。。。

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
 8 #include
 9 #include
10 #include
11 using namespace std;
12 typedef long long LL;
13 const int inf = 0x3f3f3f3f;
14 const int MAX = 1e5+10;
15 const int MOD = 100000007;
16 int a[MAX];
17 int main()
18 {
19     int n; int tot,sum;
20     while(scanf("%d",&n)==1)
21     {
22         tot=sum=0int ans=0;
23         for(int i=0;i24         {
25             scanf("%d",&a[i]);
26             if(a[i]==-1)
27             {
28                 if(sum!=0) sum--;
29                 else ans++;
30             }
31             else 
32             {
33                 sum+=a[i];
34             }
35         }
36         printf("%d\n",ans);
37     }
38     return 0;
39 }
bubuko.com,布布扣

 

 

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 
 8 #include 
 9 #include
10 #include
11 #define max(a,b) ((a>b)?a:b)
12 #define min(a,b) (a13 
14 using namespace std;
15 const int maxn = 200000 + 5;
16 const int maxlog = 30;
17 struct RMQ {
18   int d[maxn][maxlog];
19   void init(const vector<int>& A) {
20     int n = A.size();
21     for(int i = 0; i < n; i++) d[i][0] = A[i];
22     for(int j = 1; (1<23       for(int i = 0; i + (1<1 < n; i++)
24         d[i][j] = max(d[i][j-1], d[i + (1<<(j-1))][j-1]);
25   }
26 
27   int query(int L, int R) {
28     int k = 0;
29     while((1<<(k+1)) <= R-L+1) k++; 
30     return max(d[L][k], d[R-(1<1][k]);
31   }
32 };
33 int a[maxn];
34 RMQ rmq;
35 int main()
36 {
37     int n,t,c; vector<int> count; int ans=0;
38     scanf("%d%d%d",&n,&t,&c);
39     for(int i=1;i<=n;i++) scanf("%d",&a[i]),count.push_back(a[i]);
40     rmq.init(count);
41     for(int i=0;i<=n-c;i++)
42     {
43        // printf("%d\n",rmq.query(i,i+c-1));
44         if(rmq.query(i,i+c-1)<=t) ans++;
45     }
46     printf("%d\n",ans);
47     return 0;

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
 8 #include
 9 #include
10 #include
11 using namespace std;
12 typedef long long LL;
13 const int inf = 0x3f3f3f3f;
14 const int MAX = 1e5+10;
15 const int MOD = 1e9+7;
16 vector<int> G[MAX],G2[MAX];
17 vector<int> S;
18 int vis[MAX],sccno[MAX],scc_cnt;
19 int cost[MAX];
20 int Min[MAX],num[MAX];
21 void add_edge(int from,int to)
22 {
23     G[from].push_back(to);
24     G2[to].push_back(from);
25 }
26 void dfs(int u)
27 {
28     if(vis[u]) return ;
29     vis[u]=1;
30     for(int i=0;i31     S.push_back(u);
32 }
33 void rdfs(itn u)
34 {
35     if(sccno[u]) return;
36     sccno[u]=scc_cnt;
37     for(int i=0;i38 }
39 int main()
40 {
41     int n,m; int a,b;
42     scanf("%d",&n);
43     for(int i=0;i"%d",&cost[i]);
44     scanf("%d",&m);
45     for(int i=0;i46     {
47         scanf("%d %d",&a,&b); a--; b--;
48         add_edge(a,b);
49     }
50     S.clear(); scc_cnt=0;
51     memset(sccno,0,sizeof(sccno));
52     memset(vis,0,sizeof(vis));
53     for(int i=0;i54     for(int i=n-1;i>=0;i--)
55     {
56         if(!sccno[S[i]]) {scc_cnt++; rdfs(S[i]);}
57     }
58     for(int i=0;i59     memset(num,0,sizeof(num));
60     for(int i=0;i61     {
62         Min[sccno[i]]=min(cost[i],Min[sccno[i]]);
63     }
64     for(int i=0;i65     {
66         if(Min[sccno[i]]==cost[i]) num[sccno[i]]++;
67     }
68     int ans=0,ret=1;
69 
70     for(int i=0;i71     {
72         ans+=Min[i];
73         ret=(ret*num[i])%MOD;
74     }
75     printf("%d %d\n",ans,ret);
76 
77     return 0;
bubuko.com,布布扣

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 /* *************

 

 

Codeforces Round #244 (Div. 2),布布扣,bubuko.com

Codeforces Round #244 (Div. 2)


推荐阅读
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 也就是|小窗_卷积的特征提取与参数计算
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了卷积的特征提取与参数计算相关的知识,希望对你有一定的参考价值。Dense和Conv2D根本区别在于,Den ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • 3.223.28周学习总结中的贪心作业收获及困惑
    本文是对3.223.28周学习总结中的贪心作业进行总结,作者在解题过程中参考了他人的代码,但前提是要先理解题目并有解题思路。作者分享了自己在贪心作业中的收获,同时提到了一道让他困惑的题目,即input details部分引发的疑惑。 ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • Redis底层数据结构之压缩列表的介绍及实现原理
    本文介绍了Redis底层数据结构之压缩列表的概念、实现原理以及使用场景。压缩列表是Redis为了节约内存而开发的一种顺序数据结构,由特殊编码的连续内存块组成。文章详细解释了压缩列表的构成和各个属性的含义,以及如何通过指针来计算表尾节点的地址。压缩列表适用于列表键和哈希键中只包含少量小整数值和短字符串的情况。通过使用压缩列表,可以有效减少内存占用,提升Redis的性能。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
author-avatar
随洋恒黯的天使
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有