Team Contests - Warmup(2016年多校热身赛,2016年黑龙江省赛)
Team Contests - Warmup
A
题意:...
思路:不会
代码:...
随机 B
题意:给n个点,问是否有一个圆上有最少n/3个点
思路:随机大法好。
代码:...
递推 C
题意:对自然数列{1,2,3,4,5,6...}进行n次操作,每次操作有一个x,意思是前x个保留,后x个删去,再x个保留,后x个删去。。。形成新的序列,问n次操作后第n个数字。
思路:(bh)我开始想二分答案,但是对于n次过程中就被删去的点就无法处理了。那么倒过来做就很方便,已知最后的位置是第n个,那么在第n次操作前的位置应该是,所以倒过来
就做好了。结果可能爆long long,用Java写大数。
关键:逆序
代码:
import java.math.*;
import java.io.*;
import java.util.*; public class Main {
static int[] a;
public static void main(String[] args) {
Scanner in = new Scanner (new BufferedInputStream (System.in));
int T = in.nextInt ();
for (int cas=1; cas<=T; ++cas) {
int n = in.nextInt ();
a = new int[10005];
for (int i=1; i<=n; ++i) {
a[i] = in.nextInt ();
}
BigInteger ans = BigInteger.valueOf(n);
for (int i=n; i>=1; --i) {
int f = 0;
if(ans.mod(BigInteger.valueOf(a[i])).compareTo(BigInteger.ZERO) == 0) {
f = 1;
}
BigInteger tmp = ans.divide(BigInteger.valueOf(a[i])).subtract(BigInteger.valueOf(f)).multiply(BigInteger.valueOf(a[i]));
ans = ans.add(tmp);
}
System.out.println (ans);
}
}
}
模拟 D
题意:炉石游戏
思路:坑。。。
代码:...
E
题意:麻将
思路:...
代码:...
离散化 F
题意:平面上有n个点,问有多少个不同位置的矩形,满足矩形四条边上的都正好有m个点。
思路:(bh)对点进行坐标离散化点归类,先从左上角开始找到在X容器里,按照y坐标排序后的前(m-1)个点,也就是左下角,同理可以找到右上角,然后从左下角和右上角出发去找右下角,看看是否重合,如果重合表示满足条件,计数即可。
代码:
ans1:
#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
int n, m; struct Point {
int x, y, id;
}p[N]; struct Node {
int v, id;
bool operator < (const Node &rhs) const {
return v < rhs.v;
}
}; std::vector<Node> X[N], Y[N];
int xs[N], ys[N];
int totx, toty; int solve() {
sort (xs, xs+totx);
totx = unique (xs, xs+totx) - xs;
sort (ys, ys+toty);
toty = unique (ys, ys+toty) - ys;
for (int i=0; i<totx; ++i) {
X[i].clear ();
}
for (int i=0; i<toty; ++i) {
Y[i].clear ();
}
for (int i=1; i<=n; ++i) {
int px = lower_bound (xs, xs+totx, p[i].x) - xs;
int py = lower_bound (ys, ys+toty, p[i].y) - ys;
X[px].push_back ((Node) {p[i].y, p[i].id});
Y[py].push_back ((Node) {p[i].x, p[i].id});
}
for (int i=0; i<totx; ++i) {
sort (X[i].begin (), X[i].end ());
}
for (int i=0; i<toty; ++i) {
sort (Y[i].begin (), Y[i].end ());
} int ret = 0;
for (int i=1; i<=n; ++i) {
Node tmp1 = (Node) {p[i].y, p[i].id};
int px = lower_bound (xs, xs+totx, p[i].x) - xs;
int vpx = lower_bound (X[px].begin (), X[px].end (), tmp1) - X[px].begin ();
if (vpx - m + 1 < 0) continue;
int vpx1 = vpx - m + 1; int ty = X[px][vpx1].v; //(p[i].x, ty)
Node tmp3 = (Node) {p[i].x, p[i].id};
int pyt = lower_bound (ys, ys+toty, ty) - ys;
int vpyt = lower_bound (Y[pyt].begin (), Y[pyt].end (), tmp3) - Y[pyt].begin ();
if (vpyt + m - 1 >= Y[pyt].size ()) continue;
int vpyt2 = vpyt + m - 1; int x = Y[pyt][vpyt2].v, y = ty; Node tmp2 = (Node) {p[i].x, p[i].id};
int py = lower_bound (ys, ys+toty, p[i].y) - ys;
int vpy = lower_bound (Y[py].begin (), Y[py].end (), tmp2) - Y[py].begin ();
if (vpy + m - 1 >= Y[py].size ()) continue;
int vpy2 = vpy + m - 1; int tx = Y[py][vpy2].v; //(tx, p[i].y)
Node tmp4 = (Node) {p[i].y, p[i].id};
int pxt = lower_bound (xs, xs+totx, tx) - xs; //now
int vpxt = lower_bound (X[pxt].begin (), X[pxt].end (), tmp4) - X[pxt].begin ();
if (vpxt - m + 1 < 0) continue;
int vpxt2 = vpxt - m + 1; int x2 = tx, y2 = X[pxt][vpxt2].v; if (x == x2 && y == y2) {
ret++;
}
}
return ret;
} int main() {
int T;
scanf ("%d", &T);
while (T--) {
scanf ("%d%d", &n, &m);
totx = toty = 0;
for (int i=1; i<=n; ++i) {
scanf ("%d%d", &p[i].x, &p[i].y);
p[i].id = i;
xs[totx++] = p[i].x;
ys[toty++] = p[i].y;
}
printf ("%d\n", solve ());
}
return 0;
}
ans2(zcj)
#include<bits/stdc++.h>
#define mk make_pair using namespace std;
typedef long long LL;
const int maxn = + ;
int n, m;
pair<int, int> xx[maxn];
vector<LL> v;
vector<int> x[maxn];
vector<int> y[maxn];
map<pair<int, int>, int> p;
int len; void solve(){
int cnt = ;
for (int i = ; i < n; i++){
if (m <= ) break;
int tx = xx[i].first;
int ty = xx[i].second;
int lenx = x[tx].size(); //表示里面有几个y
int leny = y[ty].size();//表示里面有几个x
if (lenx < m) continue;
if (leny < m) continue;
//先找x上方的m-1个,里面放着y
int py = lower_bound(x[tx].begin(), x[tx].end(), ty) - x[tx].begin();//在x的集合里面,y的位置
if (py + m > lenx) continue;
int px = lower_bound(y[ty].begin(), y[ty].end(), tx) - y[ty].begin();//在y这个集合里面,x的位置
if (px + m > leny) continue;
int posx = y[ty][px + m - ];
int posy = x[tx][py + m - ];//this?
if (p[mk(posx, posy)]){
cnt++;
}
}
printf("%d\n", cnt);
} int main(){
int t; cin >> t;
while (t--){
scanf("%d%d", &n, &m);
for (int i = ; i < n; i++){
LL a, b;
scanf("%I64d%I64d", &a, &b);
xx[i] = mk(a, b);
v.push_back(a);
v.push_back(b);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
int lx = , ly = ;
for (int i = ; i < n; i++){
int tx = xx[i].first = lower_bound(v.begin(), v.end(), xx[i].first) - v.begin();
int ty = xx[i].second = lower_bound(v.begin(), v.end(), xx[i].second) - v.begin();
//printf("%d %d\n", xx[i].first, xx[i].second);
p[mk(tx, ty)] = ;
x[tx].push_back(ty);
y[ty].push_back(tx);
lx = max(lx, tx);
ly = max(ly, ty);
}
for (int i = ; i <= lx; i++){
sort(x[i].begin(), x[i].end());
}
for (int i = ; i <= ly; i++){
sort(y[i].begin(), y[i].end());
}
solve();
//初始化
p.clear();
v.clear();
for (int i = ; i <= lx; i++){
x[i].clear();
}
for (int i = ; i <= ly; i++){
y[i].clear();
}
memset(xx, , sizeof(xx));
}
return ;
}
G
题意:问[L, R]有多个数字的所有数位相加和是素数的个数。
思路:(bh)数位DP即可,写太着急,long long写成int。。。
代码:
#include <bits/stdc++.h>
typedef long long ll;
bool is_prime(int x) {
if (x < 2) return false;
if (x == 2 || x == 3) return true;
if (x % 6 != 1 && x % 6 != 5) return false;
for (int i=5; i*i<=x; i+=6) {
if (x % i == 0 || x % (i + 2) == 0) return false;
}
return x != 1;
}
ll dp[20][10][200];
int bit[20];
ll DFS(int pos, int pre, int sum, bool limit) {
if (pos == -1) {
return is_prime (sum);
}
ll now = dp[pos][pre][sum];
if (now != -1 && !limit) {
return now;
}
ll ret = 0;
int d = limit ? bit[pos] : 9;
for (int i=0; i<=d; ++i) {
ret += DFS (pos - 1, i, sum + i, limit && i == d);
}
if (!limit) {
dp[pos][pre][sum] = ret;
}
return ret;
}
ll solve(ll n) {
if (n <= 0) {
return 0;
}
int c = 0;
for (; n>0; n/=10) bit[c++] = n % 10;
return DFS (c - 1, 0, 0, true);
}
int main() {
memset (dp, -1, sizeof (dp));
int T;
scanf ("%d", &T);
while (T--) {
ll a, b;
scanf ("%I64d%I64d", &a, &b);
printf ("%I64d\n", solve (b) - solve (a - 1));
}
return 0;
}
H
题意:税收
思路:...
代码:...
I
题意:图论
思路:...
代码:...
Team Contests - Warmup(2016年多校热身赛,2016年黑龙江省赛)的更多相关文章
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- 2016暑假多校联合---Substring(后缀数组)
2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...
- 2016暑假多校联合---To My Girlfriend
2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- 2016暑假多校联合---Another Meaning
2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- 2016暑假多校联合---Death Sequence(递推、前向星)
原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...
- 2016暑假多校联合---Counting Intersections
原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...
随机推荐
- Codevs1082 线段树练习 3
题目描述 Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[a,b]的数的和. 输入描述 Input Description 第一行一个正整数n,接下 ...
- 【莫队】bzoj4542: [Hnoi2016]大数
挺有意思的,可以仔细体味一下的题:看白了就是莫队板子. Description 小 B 有一个很大的数 S,长度达到了 N 位:这个数可以看成是一个串,它可能有前导 0,例如00009312345.小 ...
- Voyager的Roles和Pemissions
以Page为例讲解: 取消admin的roles下Pages的Browse Pages权限: 打开web.php文件,添加: Route::get('pages', function(){ retur ...
- jmeter操作mysql数据库
1.导入jdbc的jar包,因为jmeter本身不能直接连接mysql,所以需要导入第三方的jar包,来连接mysql 2.创建数据库连接配置,mysql的url.端口号.账号.密码 在JDBC Co ...
- cols
题目描述 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩阵中 ...
- java的一些相关介绍(2013-10-07-163 写的日志迁移
java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaSE, JavaEE, Jav ...
- python爬虫基础16-cookie在爬虫中的应用
Cookie的Python爬虫应用 Cookie是什么 Cookie,有时也用其复数形式 Cookies,英文是饼干的意思.指某些网站为了辨别用户身份.进行 session 跟踪而储存在用户本地终端上 ...
- python并发编程之进程1(守护进程,进程锁,进程队列)
进程的其他方法 P = Process(target=f,) P.Pid 查看进程号 查看进程的名字p.name P.is_alive() 返回一个true或者False P.terminate( ...
- solr配置中文分词器
配置IK分词器 在/opt/solr-7.7.1/server/solr-webapp/webapp/WEB-INF/lib目录中加入IK分词器的jar包 在/opt/solr-7.7.1/serve ...
- oracle如何保证读一致性 第一弹
oracle保证读一致性原理 1:undo segment的概念 当数据库进行修改的时候,需要把保存到以前的old的数据保存到一个地方,然后进行修改,用于保存o ...