A - Garden


Time limit : 2sec / Memory limit : 1000MB

Score: 100 points

Problem Statement

There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)

What is the area of this yard excluding the roads? Find it.

Note

It can be proved that the positions of the roads do not affect the area.

Constraints

  • A is an integer between 2 and 100 (inclusive).
  • B is an integer between 2 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

A B

Output

Print the area of this yard excluding the roads (in square yards).


Sample Input 1

Copy
2 2

Sample Output 1

Copy
1

In this case, the area is 1 square yard.


Sample Input 2

Copy
5 7

Sample Output 2

Copy
24

In this case, the area is 24 square yards.

容斥定理。

代码:

import java.util.*;

public class Main {

    public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
System.out.println(a * b - a - b + 1);
}
}

B - 105


Time limit : 2sec / Memory limit : 1000MB

Score: 200 points

Problem Statement

The number 105 is quite special - it is odd but still it has eight divisors. Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?

Constraints

  • N is an integer between 1 and 200 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print the count.


Sample Input 1

Copy
105

Sample Output 1

Copy
1

Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.


Sample Input 2

Copy
7

Sample Output 2

Copy
0

1 has one divisor. 35 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.

代码:

import java.util.*;

public class Main {
static int get(int a) {
int b = 2;
for(int i = 3;i <= a / 3;i += 2) {
if(a % i == 0) {
b ++;
}
}
return b;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int m = 0;
if(a >= 105)m ++;
for(int i = 107;i <= a;i += 2) {
if(get(i) == 8)m ++;
}
System.out.println(m);
}
}

C - To Infinity


Time limit : 2sec / Memory limit : 1000MB

Score: 300 points

Problem Statement

Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:

  • Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 3334 becomes 44445 becomes 555556 becomes 6666667 becomes 77777778 becomes 88888888 and 9 becomes 9999999991 remains as 1.

For example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next. You are interested in what the string looks like after 5×1015 days. What is the K-th character from the left in the string after 5×1015 days?

Constraints

  • S is a string of length between 1 and 100 (inclusive).
  • K is an integer between 1 and 1018 (inclusive).
  • The length of the string after 5×1015 days is at least K.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the K-th character from the left in Mr. Infinity's string after 5×1015 days.


Sample Input 1

Copy
1214
4

Sample Output 1

Copy
2

The string S changes as follows:

  • Now: 1214
  • After one day: 12214444
  • After two days: 1222214444444444444444
  • After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444

The first five characters in the string after 5×1015 days is 12222. As K=4, we should print the fourth character, 2.


Sample Input 2

Copy
3
157

Sample Output 2

Copy
3

The initial string is 3. The string after 5×1015 days consists only of 3.


Sample Input 3

Copy
299792458
9460730472580800

Sample Output 3

Copy
2
只需要看看开头有几个连续的1即可。
代码:
import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
long a = in.nextLong();
int b = 0;
for(int i = 0;i < s.length();i ++) {
if(s.charAt(i) == '1')b ++;
else break;
}
if(b >= a)System.out.println(1);
else System.out.println(s.charAt(b));
}
}

D - AtCoder Express 2


Time limit : 3sec / Memory limit : 1000MB

Score: 400 points

Problem Statement

In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 123, ..., N from west to east. A company called AtCoder Expresspossesses M trains, and the train i runs from City Li to City Ri (it is possible that Li=Ri). Takahashi the king is interested in the following Q matters:

  • The number of the trains that runs strictly within the section from City pi to City qi, that is, the number of trains j such that piLj and Rjqi.

Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.

Constraints

  • N is an integer between 1 and 500 (inclusive).
  • M is an integer between 1 and 200 000 (inclusive).
  • Q is an integer between 1 and 100 000 (inclusive).
  • 1≤LiRiN (1≤iM)
  • 1≤piqiN (1≤iQ)

Input

Input is given from Standard Input in the following format:

N M Q
L1 R1
L2 R2
:
LM RM
p1 q1
p2 q2
:
pQ qQ

Output

Print Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City pi to City qi.


Sample Input 1

Copy
2 3 1
1 1
1 2
2 2
1 2

Sample Output 1

Copy
3

As all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.


Sample Input 2

Copy
10 3 2
1 5
2 8
7 10
1 7
3 10

Sample Output 2

Copy
1
1

The first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1. The second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.


Sample Input 3

Copy
10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10

Sample Output 3

Copy
7
9
10
6
8
9
6
7
8
10
简单的区间dp。
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,q;
int dp[][];
int main() {
int a,b;
scanf("%d%d%d",&n,&m,&q);
for(int i = ;i < m;i ++) {
scanf("%d%d",&a,&b);
dp[a][b] ++;
}
for(int j = ;j < n;j ++) {
for(int i = ;i + j <= n;i ++) {
int k = i + j;
dp[i][k] += dp[i + ][k] + dp[i][k - ];
if(j > )dp[i][k] -= dp[i + ][k - ];
}
}
for(int i = ;i < q;i ++) {
scanf("%d%d",&a,&b);
printf("%d\n",dp[a][b]);
}
return ;
}

树状数组,区间向两侧更新,最后查询两侧向内查询。

代码:

#include <iostream>
#include <cstdio>
using namespace std;
int n;
int sum[][];
int lowbit(int x) {
return x&-x;
}
void update(int x,int y) {
for(int i = x;i > ;i -= lowbit(i)) {
for(int j = y;j <= n;j += lowbit(j)) {
sum[i][j] ++;
}
}
}
int get(int x,int y) {
int ans = ;
for(int i = x;i <= y;i += lowbit(i)) {
for(int j = y;j >= x;j -= lowbit(j)) {
ans += sum[i][j];
}
}
return ans;
}
int main() {
int m,q;
scanf("%d%d%d",&n,&m,&q);
int a,b;
for(int i = ;i < m;i ++) {
scanf("%d%d",&a,&b);
update(a,b);
}
for(int i = ;i < q;i ++) {
scanf("%d%d",&a,&b);
printf("%d\n",get(a,b));
}
}

也可以用邻接表加二分遍历,不过就比较麻烦了。

AtCoder Beginner Contest 106 2018/08/18的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  2. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  3. 题解 AtCoder Beginner Contest 168

    小兔的话 欢迎大家在评论区留言哦~ AtCoder Beginner Contest 168 A - ∴ (Therefore) B - ... (Triple Dots) C - : (Colon) ...

  4. AtCoder Beginner Contest 169 题解

    AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...

  5. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  6. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  7. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  8. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  9. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

随机推荐

  1. ubuntu 12.10 笔记

    笔记 more ec_unitouch.log |grep Thread-4 筛选日志 打开命令行终端 ctrl + alt + t     查看版本号 : sudo lsb_release -a t ...

  2. python 基础 8.1 r 正则对象

                                                                                                        ...

  3. 八大排序的python实现

    以下是八大排序的python实现,供以后参考,日后扩展 一.插入排序 #-*- coding:utf-8 -*- ''' 描述 插入排序的基本操作就是将一个数据插入到已经排好序的有序数据中,从而得到一 ...

  4. Angular入门(二) 服务

    目的:为了不再把相同的代码复制一遍又一遍,我们要创建一个单一的可复用的数据服务,并且把它注入到需要它的那些组件中. ※  文件命名约定:服务名称的小写形式(基本名),加上.service后缀,如果服务 ...

  5. Software-defined networking

    Software-defined networking administrators to programmatically initialize, control, change, and mana ...

  6. 远程服务器上的weblogic项目管理(四)filelock not found错误解决方法

    重启weblogic时如果有残余进程没有kill,启动时便可能会造成filelock not found,文件锁未找到错误,解决方法如下: 删掉Domain下的*.lok文件:(如果不熟悉文件路径推荐 ...

  7. Grunt学习笔记【6】---- grunt-contrib-requirejs插件详解

    本文主要讲如何使用Grunt实现RequireJS文件压缩. 一 说明 ES6出来前,RequireJS是JavaScript模块化最常用的方式之一.对于使用RequireJS构建的项目,要实现打包压 ...

  8. linux日志系统介绍 —— syslog(),openlog(),closelog()

    函数使用介绍 这里面的三个函数openlog, syslog.closelog是一套系统日志写入接口.另外那个vsyslog和syslog功能一样,仅仅是參数格式不同.         通常.sysl ...

  9. Java反射详解(转)

    原文地址:http://www.importnew.com/17616.html 动态语言 动态语言,是指程序在运行时可以改变其结构:新的函数可以被引进,已有的函数可以被删除等在结构上的变化.比如众所 ...

  10. 负载均衡,会话保持,session同步(转)

    一,什么负载均衡一个新网站是不要做负载均衡的,因为访问量不大,流量也不大,所以没有必要搞这些东西.但是随着网站访问量和流量的快速增长,单台服务器受自身硬件条件的限制,很难承受这么大的访问量.在这种情况 ...