CodeForces336 A & B
第一题就是排序然后计算一下时间。没什么
package codeforces336; import java.io.InputStreamReader;
import java.util.Scanner; public class MainA {
public static void sortArr(int[][] arr, int n) {
int[] tmp = new int[2];
for(int i = 0; i < n; ++i) {
for(int j = i+1; j < n; ++j) {
if(arr[i][0] < arr[j][0]) {
tmp[0] = arr[i][0];
tmp[1] = arr[i][1];
arr[i][0] = arr[j][0];
arr[i][1] = arr[j][1];
arr[j][0] = tmp[0];
arr[j][1] = tmp[1];
}
}
}
} public static void main(String[] args) {
int n, s;
int[][] arr = new int[105][2];
Scanner sc = new Scanner(new InputStreamReader(System.in));
n = sc.nextInt();
s = sc.nextInt();
for(int i = 0; i < n; ++i) {
arr[i][0] = sc.nextInt();
arr[i][1] = sc.nextInt();
} sortArr(arr, n);
int t = 0;
int[] tmp = new int[2];
for(int i = 0; i < n; ++i) {
tmp[0] = s - arr[i][0];
tmp[1] = arr[i][1];
if(tmp[1] < (t + tmp[0])){
t += tmp[0];
} else {
t = tmp[1];
}
s = arr[i][0];
}
if(s != 0) {
t += s;
}
System.out.println(t);
}
}
第二题,暴力肯定TLE,用前缀和算可以。看a的每一位,是0,统计在 lenb - lena + i ~ i - 1 范围内 1的 个数;是 1,统计在 lenb - lena + i ~ i - 1 范围内 0 的 个数
package codeforces336; import java.io.InputStreamReader;
import java.util.Scanner; /**
* Created by lenovo on 2016-01-28.
*/
public class MainB {
public static void main(String[] args) {
String a;
String b;
Scanner sc = new Scanner(new InputStreamReader(System.in));
a = sc.nextLine();
b = sc.nextLine();
//System.out.println(a + " " + b);
long[][] pre = new long[200005][2];
int lena = a.length();
int lenb = b.length(); for(int i = 1; i <= lenb; ++i) {
if(b.charAt(i-1) == '1'){
pre[i][1] = pre[i-1][1] + 1;
pre[i][0] = pre[i-1][0];
}else {
pre[i][0] = pre[i-1][0] + 1;
pre[i][1] = pre[i-1][1];
}
}
long ans = 0;
for(int i = 1; i <= lena; ++i) {
if(a.charAt(i-1) == '0') {
ans += pre[lenb - lena + i][1] - pre[i-1][1];
} else {
ans += pre[lenb - lena + i][0] - pre[i-1][0];
}
}
System.out.println(ans);
}
}
CodeForces336 A & B的更多相关文章
随机推荐
- python调用其他程序或脚本方法(转)
python运行(调用)其他程序或脚本 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其他脚本,或者程序提供的功能,而不必再次编写实现该功能的代码.为了更好地 ...
- ES6学习笔记二
字符串遍历 var str = 'hello'; for(let s of str){console.log(s += ' ')} //h e l l o 字符串查找:添加了include(str,i ...
- PX 和PT的区别
字体大小的设置单位,常用的有2种:px.pt.这两个有什么区别呢? 先搞清基本概念:px就是表示pixel,像素,是屏幕上显示数据的最基本的点: pt就是point,是印刷行业常用单位,等于1/72英 ...
- Linux下的压缩和解压缩命令——gzip/gunzip
gzip命令 gzip命令用来压缩文件.gzip是个使用广泛的压缩程序,文件经它压缩过后,其名称后面会多处".gz"扩展名. gzip是在Linux系统中经常使用的一个对文件进行压 ...
- CROSS APPLY应用实例
--功能说明:统计每个人的平均分数,新字段[AVG_Score]根据PersonID链接到原表[tbiz_AssScore]上 SELECT [ID] ,[ProjectID] ,[PersonID] ...
- 使用Dir,遍历文件夹下所有子文件夹及文件
'------------------------------------------- '获取某文件夹下所有文件和子目录下的文件 '--------------------------------- ...
- js调用php和php调用js的方法举例
js调用php和php调用js的方法举例1 JS方式调用PHP文件并取得php中的值 举一个简单的例子来说明: 如在页面a.html中用下面这句调用: <script type="te ...
- SQL 表连接查询出现重复列,由此理清LEFT JOIN、INNER JOIN的区别
1.先创建两个临时表,并插入数据 CREATE TABLE #TEMP1( ID INT IDENTITY(1,1) PRIMARY KEY, name NVARCHAR(50)) CREATE TA ...
- MVC 添加Area
在MVC项目中经常会使用到Area来分开不同的模块让项目结构更加的清晰. 步骤如下: 项目 –> 添加 -> 区域 ( Area ) 输入 Admin 添加成功后 Area包含: 创建一个 ...
- MFC序列化与反序列化
#pragma once #include "afx.h" #include <vector> using std::vector; class HzyData : p ...