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

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. Latex使用整理

    \section{software academy}(标题) \subsection{software enginner} (小标题) \subsection{computer science} \s ...

  2. HTML5 图片本地压缩上传插件「localResizeIMG」

    移动应用中用户往往需要上传照片,但是用户上传的照片尺寸通常很大,而手机的流量却很有限,所以在上传前对图像进行压缩是很有必要的. 原生应用可以直接对文件进行处理,网页应用就没有这个优势了.不过 canv ...

  3. xampp 下安装mysql-python

    pip install mysql-python修改路径PATH="$PATH":(/mysql/bin 路径)brew install mysql-connector-c

  4. idea开发工具破解地址

    链接失效可以使用激活码.激活码不需要联网也可以开发. idea 在注册时选择 License server ,填http://idea.iteblog.com/key.php ,然后点击激活. 激活码 ...

  5. mysql 基础使用

    mysql服务器本地root用户默认没有密码,使用 "mysql -u root -p" 即可登陆.linux本地用户可以以任意用户名登陆mysql,但是没有任何权限,没有意义.m ...

  6. cmd连接mysql的方法详解(转载)

    连接:mysql -h主机地址 -u用户名 -p用户密码 (注:u与root可以不用加空格,其它也一样)断开:exit (回车) 创建授权:grant select on 数据库.* to 用户名@登 ...

  7. WEB 用户指南 -- WEB 系统结构文档

    本文描述了如何使用 WEB语言 编程.同时还包含了 WEAVE 和 TANGLE 程序的说明文档. WEB 程序 可以读取 WEB 文件,然后输出 TeX 文档 和 Pascal 程序. 使用 WEB ...

  8. check time period

    /**     * @author etao     * @description check last time selected     * @param timePeriod     * @pa ...

  9. 定位以及z-index

    定位 定位用来控制元素的位置 定位的关键字是position,position有4个值,分别是relative,absolute,static,fixed当元素定位以后,元素有4个值可以用,分别是le ...

  10. LINUX 6.x 内核升级全过程

    1. 准备工作 确认内核及版本信息 [root@hostname ~]# uname -r 2.6.32-220.el6.x86_64 [root@hostname ~]# cat /etc/cent ...