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的更多相关文章
随机推荐
- SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE configurationPUBLIC &qu ...
- 基于vw的响应式排版布局
html{ /*iphone6的375px尺寸作为16px基准,600px时字体大小为18px*/ font-size: calc(100% + 2 * (100vw - 375px) / 225); ...
- 在JaveWeb项目中配置Spring 匿名访问时,匹配规则的变相实现/*
实现/* /** * 根据当前的URL返回该url的角色集合. * 1.如果当前的URL在匿名访问的URL集合当中时,在当前的角色中添加匿名访问的角色(SysRole.ROLE_CONFIG_ANON ...
- 前端构建工具的用法—grunt、gulp、browserify、webpack
随着前端项目的飞速发展,项目越来越大.文件越来越多,前端工程化的工具也越来越多.下面介绍目前最流行的四种构建工具——grunt.gulp.browserify.webpack 所有的构建工具都是基于N ...
- js面向对象
什么事面向对象 用对象的思想去写代码,就是面向对象编程 面向对象编程(OOP)的特点 抽象:抓住核心问题 封装:只能通过对象来访问方法 继承:从已有对象上继承出新的对象 多态:多对象的不同形态 对象的 ...
- angularJS实践过程中出现的问题总结
同名服务 在一次项目里,之前是同事写的.我有一次在异步获取服务器上的数据时,习惯把api地址写在一个服务Store里,但是程序总是返回Store.api.get()里的get is undefined ...
- AlloyTouch插件
1.老样子引入js <script src="js/transform.js"></script> <script src="js/allo ...
- centos 编程环境
1,老毛桃/大白菜, iso制作将镜像文件写入u盘2, 安装,修改安装源路径 (手动修改为你的u盘dev)一般为sdb43, 安装时选择桌面安装 4, 更改安装源cd /etc/yum.repos ...
- (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)
--------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...
- 将十进制数转为一个n位数的密码(每位都是个m进制数)
例如一个6位数的10进制密码,共有106个密码,如果把每个6位数的密码编成号就是[0,106-1].这是十进制的情况,即6个位,每个位有10种选择.如果要遍历所有密码,需要6重for循环,每个循环10 ...