第一题就是排序然后计算一下时间。没什么

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的更多相关文章

随机推荐

  1. 第3月第19天 cxx_destruct dispatch_get_main_queue()死锁

    1. http://blog.jobbole.com/65028/ 2. - (void)viewDidLoad { [super viewDidLoad]; NSLog("); dispa ...

  2. User space 与 Kernel space

    学习 Linux 时,经常可以看到两个词:User space(用户空间)和 Kernel space(内核空间). 简单说,Kernel space 是 Linux 内核的运行空间,User spa ...

  3. jquery.nicescroll.js可全屏可改滚动条颜色的滚动条插件-推荐

    有一款很棒的插件 http://www.ijquery.cn/?p=666

  4. 在Extjs中对日期的处理,以及在后端数据在SQL语句的判断处理

    jsp页面可选择时间: { xtype : 'datefield', id : 'START_CREATION_DATE_', format : 'Y-m-d H:i:s', submitFormat ...

  5. Android控制ScrollView滚动

    有两种办法,第一种,使用scrollTo(),这个方法不需要handler,直接调用就行 第二种方式,使用fullScrol() 下面我们看一下这个函数: scrollView.fullScroll( ...

  6. word20161220

    S/MIME, Secure Multipurpose Internet Mail Extensions / 安全多用途网际邮件扩展协议 SACL, system access control lis ...

  7. Eclipse设置黑色主题

    1点击help--->install new software 2输入 http://eclipse-color-theme.github.com/update 3下载安装eclipse col ...

  8. Objective-C中的浅拷贝和深拷贝(转载)

    本文转自:http://segmentfault.com/blog/channe/1190000000604331 浅拷贝 浅拷贝就是对内存地址的复制,让目标对象指针和源对象指向同一片内存空间.如: ...

  9. xpath定位中starts-with、contains和text()的用法

    starts-with 顾名思义,匹配一个属性开始位置的关键字 contains 匹配一个属性值中包含的字符串 text() 匹配的是显示文本信息,此处也可以用来做定位用 eg //input[sta ...

  10. 那些PHP中没有全称的简写

    PHP中的GD库,全网没发现GD二字母的全称是什么,包括PHP.net,都搜不到GD.G应该是graphi,D是什么? die: 从php_mysql.dll到php_mysqli的变化,那个i是什么 ...