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

 
 
签到题qwq
AB同位均为1时异或为0,其余不管。
注意C为正整数,故若C0则令其为1
 
 1 #include 
 2 #include 
 3 #include 
 4 #define MIN(a,b) (a)<(b)?(a):(b)
 5 #define MAX(a,b) (a)>(b)?(a):(b)
 6 #define ABS(a) (a)>0?(a):-(a)
 7 #define fo(i,a,b) for (int i=(a);i<=(b);++i)
 8 #define fod(i,a,b) for (int i=(a);i>=(b);--i)
 9 #define rep(i,a,b) for (int i=(a);i<(b);++i)
10 #define repd(i,a,b) for (int i=(a);i>(b);--i)
11 typedef long long LL;
12 using namespace std;
13 LL a,b,c;
14 int t,cnt;
15 void readint(int &x){
16     x=0;
17     int w=1;
18     char c;
19     for (c=getchar();c<'0'||c>'9';c=getchar()) if (c=='-') w=-1;
20     for (;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
21     x*=w; 
22 }
23 void readlong(LL &x){
24     x=0;
25     LL w=1;
26     char c;
27     for (c=getchar();c<'0'||c>'9';c=getchar()) if (c=='-') w=-1;
28     for (;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
29     x*=w; 
30 }
31 int main(){
32     readint(t);
33     while (t--){
34         readlong(a);
35         readlong(b);
36         cnt=0;
37         c=0;
38         while (a>0&&b>0){
39             if ((a&1)&&(b&1)) c+=(1LL<<cnt);
40             ++cnt;
41             a>>=1;
42             b>>=1;
43         }
44         if(c==0)++c;
45         printf("%lld\n",c);
46     }
47     return 0;
48 }
神奇的代码

 

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
For each instruction in format 2 , output the answer in one line.
 
Sample Input
3

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

 
Sample Output

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

 
注意a数组其实是n的一个排列,操作一相当于删除某一数。
由于询问区间左端是固定的,一开始想主席树,但涉及修改要树状数组套主席树然后就log方就T
主席树储存的值要不就是0要不就是1,我们可以转换储存信息,把储存的信息改为下标,然后建棵权值线段树,问题即可转换为求[k,n]区间里,下标大于r的最小值,复杂度就玄学O(mlogn)
 
  1 #include 
  2 #include 
  3 #include 
  4 #include 
  5 #include 
  6 #include 
  7 #include 
  8 #include  
  9 #define MIN(a,b) (((a)<(b)?(a):(b)))
 10 #define MAX(a,b) (((a)>(b)?(a):(b)))
 11 #define ABS(a) (((a)>0?(a):-(a)))
 12 #define debug(a) printf("a=%d\n",a);
 13 #define fo(i,a,b) for (int i=(a);i<=(b);++i)
 14 #define fod(i,a,b) for (int i=(a);i>=(b);--i)
 15 #define rep(i,a,b) for (int i=(a);i<(b);++i)
 16 #define red(i,a,b) for (int i=(a);i>(b);--i)
 17 #define smess int root,int l,int r
 18 #define lson root<<1
 19 #define rson root<<1|1
 20 #define lsth root<<1,l,mid
 21 #define rsth root<<1|1,mid+1,r
 22 #define N 100040
 23 typedef long long LL;
 24 using namespace std;
 25 int t,n,m,pos[N],lastans,maxx[N*4],f[N],a,b,ans;
 26 void readint(int &x){
 27     x=0;
 28     char c;
 29     int w=1;
 30     for (c=getchar();c<'0'||c>'9';c=getchar())
 31         if (c=='-') w=-1;
 32     for (;c>='0'&&c<='9';c=getchar())
 33         x=(x<<3)+(x<<1)+c-'0';
 34     x*=w;
 35 }
 36 void readlong(long long &x){
 37     x=0;
 38     char c;
 39     long long w=1;
 40     for (c=getchar();c<'0'||c>'9';c=getchar())
 41         if (c=='-') w=-1;
 42     for (;c>='0'&&c<='9';c=getchar())
 43         x=(x<<3)+(x<<1)+c-'0';
 44     x*=w;
 45 }
 46 void build(smess){
 47     if (l==r){
 48         maxx[root]=pos[l];
 49         return;
 50     }
 51     int mid=(l+r)>>1;
 52     build(lsth);
 53     build(rsth);
 54     maxx[root]=MAX(maxx[lson],maxx[rson]);
 55 }
 56 void updata(smess,int pp){
 57     if (l==r){
 58         maxx[root]=n+pp;
 59         return;
 60     }
 61     int mid=(l+r)>>1;
 62     if (pp<=mid) updata(lsth,pp);
 63     else updata(rsth,pp);
 64     maxx[root]=MAX(maxx[lson],maxx[rson]);
 65 }
 66 int query(smess,int ll,int pp){
 67     int qaq=0;
 68     if (l==r) if (l>=ll&&maxx[root]>pp) return l;
 69     else return 0;
 70     int mid=(l+r)>>1;
 71     if (maxx[lson]>pp&&mid>=ll)  qaq=query(lsth,ll,pp);
 72     if (qaq==0) qaq=query(rsth,ll,pp);
 73     return qaq;
 74 }
 75 int main(){
 76     readint(t);
 77     while (t--){
 78         ans=0;
 79         readint(n);
 80         readint(m);
 81         fo(i,1,n) {readint(f[i]);pos[f[i]]=i;}
 82         pos[n+1]=n+233;
 83         build(1,1,n+1);
 84         fo(i,1,m){
 85             readint(a);
 86             if (a==1){
 87                 readint(a);
 88                 a^=ans;
 89                 updata(1,1,n+1,f[a]);
 90             }
 91             else{
 92                 readint(a);readint(b);
 93                 a^=ans;
 94                 b^=ans;
 95                 ans=query(1,1,n+1,b,a);
 96                 printf("%d\n",ans);
 97             }
 98         }
 99     }
100     return 0;
101 }
神奇的代码

 

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

 1 #include 
 2 using namespace std;
 3 const int maxn=1e5+10;
 4 
 5 int n,m,a[maxn],q[maxn];
 6 bool vis[maxn];
 7 
 8 int main(){
 9     scanf("%d%d",&n,&m);
10     for(int i=1;i<=n;i++){
11         scanf("%d",&a[i]);
12     }
13     for(int i=1;i<=m;i++){
14         scanf("%d",&q[i]);
15     }
16     for(int i=m;i>=1;i--){
17         if(!vis[q[i]]){
18             printf("%d ",q[i]);
19             vis[q[i]]=1;
20         }
21     }
22     for(int i=1;i<=n;i++){
23         if(!vis[a[i]]){
24             printf("%d ",a[i]);
25             vis[a[i]]=1;
26         }
27     }
28     return 0;
29 }
神奇的代码

 

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:

 2019CCPC网络赛_第1张图片

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

 1 #include 
 2 using namespace std;
 3 
 4 const int maxn = 1024;
 5 char A[maxn][maxn];
 6 
 7 void Build (void) {
 8     A[0][0] = 'C';
 9     A[0][1] = 'C';
10     A[1][0] = 'C';
11     A[1][1] = 'P';
12     for (int k = 2; k <= 10; k++) {
13         int a = 1 << (k - 1);
14         int b = (1 << k) - 1;
15         for (int i = 0; i <= a - 1; i++)
16             for (int j = a; j <= b; j++)
17                 A[i][j] = A[i][j - a];
18         for (int i = a; i <= b; i++)
19             for (int j = 0; j <= a - 1; j++)
20                 A[i][j] = A[i - a][j];
21         for (int i = a; i <= b; i++)
22             for (int j = a; j <= b; j++)
23                 A[i][j] = A[i - a][j - a] == 'C' ? 'P' : 'C';
24     }
25 }
26 
27 main (void) { //by ZTQ
28     //freopen("input.txt", "r", stdin);
29     Build();
30     int kase,k;
31     scanf("%d",&kase);
32     while (kase--) {
33         scanf("%d",&k);
34         int n=(1 << k) - 1;
35         for (int i=0;i<=n;i++) {
36             for (int j=n;j>=0;j--)
37                 printf("%c",A[i][j]);
38             printf("\n");
39         }
40     }
41 }
神奇的代码

 

 

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个数加到答案里即为最小的所花时间了。

 

 1 #include 
 2 using namespace std;
 3 
 4 const int maxn=1e5;
 5 long long ans,N,K,T[maxn+1],X[maxn+1],remain;
 6 
 7 void Read (void) {
 8     scanf("%d %lld",&N,&K);
 9     ans=K;
10     remain=N-1;
11     for (int i=1;i<=N;i++) {
12         scanf("%lld",&T[i]);
13         ans+=T[i];
14         remain-=T[i]/K;
15         X[i]=K-T[i]%K;
16     }
17     sort(X+1,X+N+1);
18 }
19 
20 void Solve (void) {
21     for (int i=1;i<=remain;i++)
22         ans+=X[i];
23     printf("%lld\n",ans);
24 }
25 
26 main (void) { //by ZTQ
27     //freopen("input.txt","r",stdin);
28     int kase;
29     scanf("%d",&kase);
30     while (kase--) {
31         Read();
32         Solve();
33     }
34 }
神奇的代码

 

 

qwq待续(不会续了)

 

 

 

转载于:https://www.cnblogs.com/Lanly/p/11409396.html

你可能感兴趣的:(java,ui)