2019CCPC网络赛
^&^ (HDU 6702)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Bit operation is a common computing method in computer science ,Now we have two positive integers A and B ,Please find a positive integer C that minimize the value of the formula (A xor C) & (B xor C) .Sometimes we can find a lot of C to do this ,So you need to find the smallest C that meets the criteria .
For example ,Let's say A is equal to 5 and B is equal to 3 ,we can choose C =1,3.... ,so the answer we're looking for C is equal to 1.
If the value of the expression is 0 when C=0, please print 1.
Input
The input file contains T test samples.(1<=T <=100)
The first line of input file is an integer T .
Then the T lines contains 2 positive integers, A and B , (1≤A,B<232 )
Output
For each test case,you should output the answer and a line for each answer.
Sample Input
1 3 5
Sample Output
1
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define MIN(a,b) (a)<(b)?(a):(b)
#define MAX(a,b) (a)>(b)?(a):(b)
#define ABS(a) (a)>0?(a):-(a)
#define fo(i,a,b) for (int i=(a);i<=(b);++i)
#define fod(i,a,b) for (int i=(a);i>=(b);--i)
#define rep(i,a,b) for (int i=(a);i<(b);++i)
#define repd(i,a,b) for (int i=(a);i>(b);--i)
typedef long long LL;
using namespace std;
LL a,b,c;
int t,cnt;
void readint(int &x){
x=;
int w=;
char c;
for (c=getchar();c<''||c>'';c=getchar()) if (c=='-') w=-;
for (;c>=''&&c<='';c=getchar()) x=(x<<)+(x<<)+(c^'');
x*=w;
}
void readlong(LL &x){
x=;
LL w=;
char c;
for (c=getchar();c<''||c>'';c=getchar()) if (c=='-') w=-;
for (;c>=''&&c<='';c=getchar()) x=(x<<)+(x<<)+(c^'');
x*=w;
}
int main(){
readint(t);
while (t--){
readlong(a);
readlong(b);
cnt=;
c=;
while (a>&&b>){
if ((a&)&&(b&)) c+=(1LL<<cnt);
++cnt;
a>>=;
b>>=;
}
if(c==)++c;
printf("%lld\n",c);
}
return ;
}
神奇的代码
array (HDU 6703)
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Problem Description
You are given an array a1,a2,...,an(∀i∈[1,n],1≤ai≤n) . Initially, each element of the array is **unique**.
Moreover, there are m instructions.
Each instruction is in one of the following two formats:
1. (1,pos) ,indicating to change the value of apos to apos+10,000,000 ;
2. (2,r,k) ,indicating to ask the minimum value which is **not equal** to any ai ( 1≤i≤r ) and **not less ** than k .
Please print all results of the instructions in format 2 .
Input
The first line of the input contains an integer T(1≤T≤10) , denoting the number of test cases.
In each test case, there are two integers n(1≤n≤100,000) ,m(1≤m≤100,000) in the first line, denoting the size of array a and the number of instructions.
In the second line, there are n distinct integers a1,a2,...,an (∀i∈[1,n],1≤ai≤n) ,denoting the array.
For the following m lines, each line is of format (1,t1) or (2,t2,t3) .
The parameters of each instruction are generated by such way :
For instructions in format 1 , we defined pos=t1⊕LastAns . (It is promised that 1≤pos≤n )
For instructions in format 2 , we defined r=t2⊕LastAns,k=t3⊕LastAns . (It is promised that 1≤r≤n,1≤k≤n )
(Note that ⊕ means the bitwise XOR operator. )
Before the first instruction of each test case, LastAns is equal to 0 .After each instruction in format 2 , LastAns will be changed to the result of that instruction.
(∑n≤510,000,∑m≤510,000 )
, output the answer in one line.
5 9
4 3 1 2 5
2 1 1
2 2 2
2 6 7
2 1 3
2 6 3
2 0 4
1 5
2 3 7
2 4 3
10 6
1 2 4 6 3 5 9 10 7 8
2 7 2
1 2
2 0 5
2 11 10
1 3
2 3 2
10 10
9 7 5 3 4 10 6 2 1 8
1 10
2 8 9
1 12
2 15 15
1 12
2 1 3
1 9
1 12
2 2 2
1 9
1
5
2
2
5
6
1
6
7
3
11
10
11
4
8
11
Hint
note:
After the generation procedure ,the instructions of the first test case are :
2 1 1, in format 2 and r=1 , k=1
2 3 3, in format 2 and r=3 , k=3
2 3 2, in format 2 and r=3 , k=2
2 3 1, in format 2 and r=3 , k=1
2 4 1, in format 2 and r=4 , k=1
2 5 1, in format 2 and r=5 , k=1
1 3 , in format 1 and pos=3
2 5 1, in format 2 and r=5 , k=1
2 5 2, in format 2 and r=5 , k=2
the instructions of the second test case are :
2 7 2, in format 2 and r=7 , k=2
1 5 , in format 1 and pos=5
2 7 2, in format 2 and r=7 , k=2
2 8 9, in format 2 and r=8 , k=9
1 8 , in format 1 and pos=8
2 8 9, in format 2 and r=8 , k=9
the instructions of the third test case are :
1 10 , in format 1 and pos=10
2 8 9 , in format 2 and r=8 , k=9
1 7 , in format 1 and pos=7
2 4 4 , in format 2 and r=4 , k=4
1 8 , in format 1 and pos=8
2 5 7 , in format 2 and r=5 , k=7
1 1 , in format 1 and pos=1
1 4 , in format 1 and pos=4
2 10 10, in format 2 and r=10 , k=10
1 2 , in format 1 and pos=2
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctime>
#include <queue>
#define MIN(a,b) (((a)<(b)?(a):(b)))
#define MAX(a,b) (((a)>(b)?(a):(b)))
#define ABS(a) (((a)>0?(a):-(a)))
#define debug(a) printf("a=%d\n",a);
#define fo(i,a,b) for (int i=(a);i<=(b);++i)
#define fod(i,a,b) for (int i=(a);i>=(b);--i)
#define rep(i,a,b) for (int i=(a);i<(b);++i)
#define red(i,a,b) for (int i=(a);i>(b);--i)
#define smess int root,int l,int r
#define lson root<<1
#define rson root<<1|1
#define lsth root<<1,l,mid
#define rsth root<<1|1,mid+1,r
#define N 100040
typedef long long LL;
using namespace std;
int t,n,m,pos[N],lastans,maxx[N*],f[N],a,b,ans;
void readint(int &x){
x=;
char c;
int w=;
for (c=getchar();c<''||c>'';c=getchar())
if (c=='-') w=-;
for (;c>=''&&c<='';c=getchar())
x=(x<<)+(x<<)+c-'';
x*=w;
}
void readlong(long long &x){
x=;
char c;
long long w=;
for (c=getchar();c<''||c>'';c=getchar())
if (c=='-') w=-;
for (;c>=''&&c<='';c=getchar())
x=(x<<)+(x<<)+c-'';
x*=w;
}
void build(smess){
if (l==r){
maxx[root]=pos[l];
return;
}
int mid=(l+r)>>;
build(lsth);
build(rsth);
maxx[root]=MAX(maxx[lson],maxx[rson]);
}
void updata(smess,int pp){
if (l==r){
maxx[root]=n+pp;
return;
}
int mid=(l+r)>>;
if (pp<=mid) updata(lsth,pp);
else updata(rsth,pp);
maxx[root]=MAX(maxx[lson],maxx[rson]);
}
int query(smess,int ll,int pp){
int qaq=;
if (l==r) if (l>=ll&&maxx[root]>pp) return l;
else return ;
int mid=(l+r)>>;
if (maxx[lson]>pp&&mid>=ll) qaq=query(lsth,ll,pp);
if (qaq==) qaq=query(rsth,ll,pp);
return qaq;
}
int main(){
readint(t);
while (t--){
ans=;
readint(n);
readint(m);
fo(i,,n) {readint(f[i]);pos[f[i]]=i;}
pos[n+]=n+;
build(,,n+);
fo(i,,m){
readint(a);
if (a==){
readint(a);
a^=ans;
updata(,,n+,f[a]);
}
else{
readint(a);readint(b);
a^=ans;
b^=ans;
ans=query(,,n+,b,a);
printf("%d\n",ans);
}
}
}
return ;
}
神奇的代码
K-th occurrence (HDU 6704)
Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Problem Description
You are given a string S consisting of only lowercase english letters and some queries.
For each query (l,r,k), please output the starting position of the k-th occurence of the substring SlSl+1...Sr in S.
Input
The first line contains an integer T(1≤T≤20), denoting the number of test cases.
The first line of each test case contains two integer N(1≤N≤105),Q(1≤Q≤105), denoting the length of S and the number of queries.
The second line of each test case contains a string S(|S|=N) consisting of only lowercase english letters.
Then Q lines follow, each line contains three integer l,r(1≤l≤r≤N) and k(1≤k≤N), denoting a query.
There are at most 5 testcases which N is greater than 103.
Output
For each query, output the starting position of the k-th occurence of the given substring.
If such position don't exists, output −1 instead.
Sample Input
2
12 6
aaabaabaaaab
3 3 4
2 3 2
7 8 3
3 4 2
1 4 2
8 12 1
1 1
a
1 1 1
Sample Output
5
2
-1
6
9
8
1
path (HDU 6705)
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
You have a directed weighted graph with n vertexes and m edges. The value of a path is the sum of the weight of the edges you passed. Note that you can pass any edge any times and every time you pass it you will gain the weight.
Now there are q queries that you need to answer. Each of the queries is about the k-th minimum value of all the paths.
Input
The input consists of multiple test cases, starting with an integer t (1≤t≤100), denoting the number of the test cases.
The first line of each test case contains three positive integers n,m,q. (1≤n,m,q≤5∗104)
Each of the next m lines contains three integers ui,vi,wi, indicating that the i−th edge is from ui to vi and weighted wi.(1≤ui,vi≤n,1≤wi≤109)
Each of the next q lines contains one integer k as mentioned above.(1≤k≤5∗104)
It's guaranteed that Σn ,Σm, Σq,Σmax(k)≤2.5∗105 and max(k) won't exceed the number of paths in the graph.
Output
For each query, print one integer indicates the answer in line.
Sample Input
1
2 2 2
1 2 1
2 1 2
3
4
Sample Output
3
3
Hint
1->2 value :1
2->1 value: 2
1-> 2-> 1 value: 3
2-> 1-> 2 value: 3
待填
huntian oy (HDU 6706)
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
One day, Master oy created a new function to celebrate his becoming a 'huntian' in majsoul.
f(n,a,b)=∑ni=1∑ij=1gcd(ia−ja,ib−jb)[gcd(i,j)=1]%(109+7)
Given n, a and b, Master oy wanted Newbie jj who was still a 'chuxin' to answer the value of f(n,a,b).
Input
There are multiple test cases.
The first line contains an integer T, indicating the number of test cases.
For each test case, there are three positive integers n, a and b which are separated by spaces. It's guaranteed that a and b are coprime.
1≤n,a,b≤109
T=104, but there are only 10 test cases that n is over 106.
Output
For each test case, an integer in one line representing your answer.
Sample Input
2
1 2 3
100 2 3
Sample Output
0
101542
疯狂化公式
待填(也许以后都不会填)
Shuffle Card (HDU 6707)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
A deck of card consists of n cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to n. We complete the shuffle process in the following way, In each operation, we will draw a card and put it in the position of the first card, and repeat this operation for m times.
Please output the order of cards after m operations.
Input
The first line of input contains two positive integers n and m.(1<=n,m<=105)
The second line of the input file has n Numbers, a sequence of 1 through n.
Next there are m rows, each of which has a positive integer si, representing the card number extracted by the i-th operation.
Output
Please output the order of cards after m operations. (There should be one space after each number.)
Sample Input
5 3
1 2 3 4 5
3
4
3
Sample Output
3 4 1 2 5
qwq签到题,操作顺序倒序输出后再按原数组顺序输出,已经输出的数就不管了qwq
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+; int n,m,a[maxn],q[maxn];
bool vis[maxn]; int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=;i<=m;i++){
scanf("%d",&q[i]);
}
for(int i=m;i>=;i--){
if(!vis[q[i]]){
printf("%d ",q[i]);
vis[q[i]]=;
}
}
for(int i=;i<=n;i++){
if(!vis[a[i]]){
printf("%d ",a[i]);
vis[a[i]]=;
}
}
return ;
}
神奇的代码
Windows Of CCPC (HDU 6708)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
In recent years, CCPC has developed rapidly and gained a large number of competitors .One contestant designed a design called CCPC Windows .The 1-st order CCPC window is shown in the figure:
And the 2-nd order CCPC window is shown in the figure:
We can easily find that the window of CCPC of order k is generated by taking the window of CCPC of order k−1 as C of order k, and the result of inverting C/P in the window of CCPC of order k−1 as P of order k.
And now I have an order k ,please output k-order CCPC Windows , The CCPC window of order k is a 2k∗2k matrix.
Input
The input file contains T test samples.(1<=T<=10)
The first line of input file is an integer T.
Then the T lines contains a positive integers k , (1≤k≤10)
Output
For each test case,you should output the answer .
Sample Input
3
1
2
3
Sample Output
CC
PC
CCCC
PCPC
PPCC
CPPC
CCCCCCCC
PCPCPCPC
PPCCPPCC
CPPCCPPC
PPPPCCCC
CPCPPCPC
CCPPPPCC
PCCPCPPC
找规律qwq
#include <bits/stdc++.h>
using namespace std; const int maxn = ;
char A[maxn][maxn]; void Build (void) {
A[][] = 'C';
A[][] = 'C';
A[][] = 'C';
A[][] = 'P';
for (int k = ; k <= ; k++) {
int a = << (k - );
int b = ( << k) - ;
for (int i = ; i <= a - ; i++)
for (int j = a; j <= b; j++)
A[i][j] = A[i][j - a];
for (int i = a; i <= b; i++)
for (int j = ; j <= a - ; j++)
A[i][j] = A[i - a][j];
for (int i = a; i <= b; i++)
for (int j = a; j <= b; j++)
A[i][j] = A[i - a][j - a] == 'C' ? 'P' : 'C';
}
} main (void) { //by ZTQ
//freopen("input.txt", "r", stdin);
Build();
int kase,k;
scanf("%d",&kase);
while (kase--) {
scanf("%d",&k);
int n=( << k) - ;
for (int i=;i<=n;i++) {
for (int j=n;j>=;j--)
printf("%c",A[i][j]);
printf("\n");
}
}
}
神奇的代码
Fishing Master (HDU 6709)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Heard that eom is a fishing MASTER, you want to acknowledge him as your mentor. As everybody knows, if you want to be a MASTER's apprentice, you should pass the trial. So when you find fishing MASTER eom, the trial is as follow:
There are n fish in the pool. For the i - th fish, it takes at least ti minutes to stew(overcook is acceptable). To simplify this problem, the time spent catching a fish is k minutes. You can catch fish one at a time and because there is only one pot, only one fish can be stewed in the pot at a time. While you are catching a fish, you can not put a raw fish you have caught into the pot, that means if you begin to catch a fish, you can't stop until after k minutes; when you are not catching fish, you can take a cooked fish (stewed for no less than ti) out of the pot or put a raw fish into the pot, these two operations take no time. Note that if the fish stewed in the pot is not stewed for enough time, you cannot take it out, but you can go to catch another fish or just wait for a while doing nothing until it is sufficiently stewed.
Now eom wants you to catch and stew all the fish as soon as possible (you definitely know that a fish can be eaten only after sufficiently stewed), so that he can have a satisfying meal. If you can complete that in the shortest possible time, eom will accept you as his apprentice and say "I am done! I am full!". If you can't, eom will not accept you and say "You are done! You are fool!".
So what's the shortest time to pass the trial if you arrange the time optimally?
Input
The first line of input consists of a single integer T(1≤T≤20), denoting the number of test cases.
For each test case, the first line contains two integers n(1≤n≤105),k(1≤k≤109), denoting the number of fish in the pool and the time needed to catch a fish.
the second line contains n integers, t1,t2,…,tn(1≤ti≤109) ,denoting the least time needed to cook the i - th fish.
Output
For each test case, print a single integer in one line, denoting the shortest time to pass the trial.
Sample Input
2
3 5
5 5 8
2 4
3 3
Sample Output
23
11
Hint
Case 1: Catch the 3rd fish (5 mins), put the 3rd fish in, catch the 1st fish (5 mins), wait (3 mins),
take the 3rd fish out, put the 1st fish in, catch the 2nd fish(5 mins),
take the 1st fish out, put the 2nd fish in, wait (5 mins), take the 2nd fish out.
Case 2: Catch the 1st fish (4 mins), put the 1st fish in, catch the 2nd fish (4 mins),
take the 1st fish out, put the 2nd fish in, wait (3 mins), take the 2nd fish out.
钓了好久的鱼
这种题果断贪心qwq
令ans=k+∑ti
每条鱼煮的时间是必不可少的。
第一条鱼肯定是需要时间钓的,然后煮鱼时间ti=mi*k+q的我们肯定选择钓mi条鱼,关键就是剩余小于k的时间q的时候我们究竟是等鱼熟了还是花额外的时间(ans会变大)多钓一条。
很显然如果∑mi大于n-1的话最终答案就是ans了。
要是不大于,我们自然是花费最少的额外时间去钓完剩下的n-∑mi条鱼
所以我们就把每条鱼煮的时间ti,如果ti大于k的话先减去k直到ti小于k,然后储存再钓一条鱼所花的额外时间k-ti,然后从小到大排序选前n-∑mi个数加到答案里即为最小的所花时间了。
#include <bits/stdc++.h>
using namespace std; const int maxn=1e5;
long long ans,N,K,T[maxn+],X[maxn+],remain; void Read (void) {
scanf("%d %lld",&N,&K);
ans=K;
remain=N-;
for (int i=;i<=N;i++) {
scanf("%lld",&T[i]);
ans+=T[i];
remain-=T[i]/K;
X[i]=K-T[i]%K;
}
sort(X+,X+N+);
} void Solve (void) {
for (int i=;i<=remain;i++)
ans+=X[i];
printf("%lld\n",ans);
} main (void) { //by ZTQ
//freopen("input.txt","r",stdin);
int kase;
scanf("%d",&kase);
while (kase--) {
Read();
Solve();
}
}
神奇的代码
qwq待续(不会续了)
2019CCPC网络赛的更多相关文章
- [2019CCPC网络赛][hdu6704]K-th occurrence(后缀数组&&主席树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6704 题意为查询子串s[l...r]第k次出现的位置. 写完博客后5分钟的更新 写完博客才发现这份代码 ...
- 2019CCPC网络赛 C - K-th occurrence HDU - 6704(后缀数组+ST表+二分+主席树)
题意 求区间l,r的子串在原串中第k次出现的位置. 链接:https://vjudge.net/contest/322094#problem/C 思路 比赛的时候用后缀自动机写的,TLE到比赛结束. ...
- 2019CCPC网络赛 HD6707——杜教筛
题意 求 $f(n,a,b)=\sum_{i=1}^n \sum_{j=1}^i gcd(i^a-j^a,i^b-j^b)[gcd(i,j)=1]\%(10^9+7)$,$1 \le n,a,b \l ...
- 2019CCPC网络赛 HDU 6702——找规律
题意 给定 $A,B$(都是正整数),求使得 $(A\ xor\ C) \& (B \ xor \ C)$ 最小的正整数 $C$,如果有多个满足条件的 $C$,输出最小的 $C$. 分析 ...
- 2019CCPC网络赛——array(权值线段树)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=6703 题目大意: 给出一个n(n<1e5)个元素的数组A,A中所有元素都是不重复的[1,n]. 有 ...
- 2019CCPC网络赛 HDU6705 - path K短路
题意:给出n个点m条边的有向图,问图上第K短路的长度是多少(这里的路可以经过任何重复点重复边). 解法:解法参考https://blog.csdn.net/Ratina/article/details ...
- 2019ccpc网络赛hdu6705 path
path 题目传送门 解题思路 先用vector存图,然后将每个vector按照边的权值从小到大排序.将每个顶点作为起点的边里最短的边存入优先队列.对于存入优先队列的信息,应有边起点,终点,是其起点的 ...
- 2019ccpc网络赛hdu6703 array(线段树)
array 题目传送门 解题思路 操作1是把第pos个位置上的数加上\(10^7\),操作2是找到区间[1,r]中没有且大于k的最小的数.注意到k的范围是小于等于n的,且n的范围是\(10^5\),远 ...
- HDU 5875 Function -2016 ICPC 大连赛区网络赛
题目链接 网络赛的水实在太深,这场居然没出线zzz,差了一点点,看到这道题的的时候就剩半个小时了.上面是官方的题意题解,打完了才知道暴力就可以过,暴力我们当时是想出来了的,如果稍稍再优化一下估计就过了 ...
随机推荐
- HTML 009 select_jquery操作下拉框select
取值问题 <select id="selector"> <option value="1">选项一</option> < ...
- CI持续集成 -- git 与 gitlab
版本控制系统概述 git Git基本概述 Git是一个免费的开源分布式版本控制系统,旨在快速高效地处理从小型到大型项目的所有内容. Git安装配置 #安装Git yum install -y git ...
- 洛谷 P1226 【模板】快速幂||取余运算 题解
Analysis 快速幂模板,注意在最后输出时也要取模. 快速幂模板 inline ll ksm(ll x,ll y) { ll ans=; ) { ) { ans*=x; ans%=k; } x*= ...
- S1_搭建分布式OpenStack集群_10 cinder 存储节点配置
一.安装配置lvm2安装LVM包:# yum install -y lvm2 启动LVM元数据服务,并将其配置为在系统启动时启动:# systemctl enable lvm2-lvmetad.ser ...
- Hdu 3037 Saving Beans(Lucus定理+乘法逆元)
Saving Beans Time Limit: 3000 MS Memory Limit: 32768 K Problem Description Although winter is far aw ...
- 49、Spark Streaming基本工作原理
一.大数据实时计算介绍 1.概述 Spark Streaming,其实就是一种Spark提供的,对于大数据,进行实时计算的一种框架.它的底层,其实,也是基于我们之前讲解的Spark Core的. 基本 ...
- D3.js的v5版本入门教程(第十二章)—— D3.js中各种精美的图形
D3.js的v5版本入门教程(第十二章) D3中提供了各种制作常见图形的函数,在d3的v3版本中叫布局,通过d3.layout.xxx,来新建,但是到了v5,新建一个d3中基本的图形的方式变了(我也并 ...
- OpenFOAM——梯形腔双边驱流
本算例来自<ANSYS Fluid Dynamics Verification Manual>中的VMFL054: Laminar flow in a Trapezoidal Cavity ...
- 微信小程序之使用wx:for遍历循环
效果图如下: 实现代码如下:type.js: // pages/type/type.js Page({ /** * 页面的初始数据 */ data: { types: "" }, ...
- hadoop作业
作业要求:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/3223 一.准备一个ubantu 系统 二.创建hadoop用户 创建 设密 ...