ACM-ICPC 2018 徐州赛区网络预赛

F. Features Track

Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat movement from a cat video. To do this, he extracts cat features in each frame. A cat feature is a two-dimension vector <x, y>. If xi = xj and yi = yj, then <xi, yi> <xj, yj> are same features.

So if cat features are moving, we can think the cat is moving. If feature <a,b> is appeared in continuous frames, it will form features movement. For example, feature <a, b> is appeared in frame 2,3,4,7,8, then it forms two features movement 2-3-4 and 7-8.

Now given the features in each frames, the number of features may be different,Morgana wants to find the longest features movement.

Input

First line contains one integer T(1 <= T <= 10), giving the test cases.Then the first line of each cases contains one integer n (number of frames),In The next n lines, each line contains one integer ki ( the number of features) and 2ki intergers describe ki features in ith frame.(The first two integers describe the first feature, the 3rd and 4th integer describe the second feature, and so on).
In each test case the sum number of features N will satisfy N <= 100000.

Output

For each cases, output one line with one integers represents the longest length of features movement.

样例输入

1
8
2 1 1 2 2
2 1 1 1 4
2 1 1 2 2
2 2 2 1 4
0
0
1 1 1
1 1 1

样例输出

3
解题思路:找出连续出现同一坐标对的最大次数即可。
AC代码:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 map<pair<int,int>,int> mp1,mp2;
 4 int t,n,k,res;
 5 int main(){
 6     while(~scanf("%d",&t)){
 7         while(t--){
 8             scanf("%d",&n);mp1.clear(),mp2.clear(),res=0;
 9             for(int i=1;i<=n;++i){
10                 scanf("%d",&k);
11                 for(int j=1;j<=k;++j){
12                     pair<int,int> pai;
13                     scanf("%d%d",&pai.first,&pai.second);
14                     if(mp1[pai]==i)continue;//防止重计算
15                     if(mp1[pai]!=i-1)res=max(res,mp2[pai]),mp2[pai]=0;
16                     mp1[pai]=i,mp2[pai]++;
17                 }
18             }
19             printf("%d\n",res);
20         }
21     }
22     return 0;
23 }

H. Ryuji doesn’t want to study

Ryuji is not a good student, and he doesn’t want to study. But there are n books he should learn, each book has its knowledge a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from l to r, he will get a[l]*L+a[l+1]*(L-1)+…+a[r-1]*2+a[r] (L is the length of [l, r] that equals to r-l+1).

Now Ryuji has qq questions, you should answer him:

1. If the question type is 1, you should answer how much knowledge he will get after he reads books [ l, r ].

2. If the question type is 2, Ryuji will change the ith book's knowledge to a new value.

Input

First line contains two integers n and q (n, q <= 100000).
The next line contains n integers represent a[i]( a[i] <= 1e9)
Then in next q line each line contains three integers a, b, c, if a = 1, it means question type is 1, and b, c represents [l, r]. if a = 2, it means question type is 2, and b, c means Ryuji changes the bth book’ knowledge to c.

Output

For each question, output one line with one integer represent the answer.

样例输入

5 3
1 2 3 4 5
1 1 3
2 5 0
1 4 5

样例输出

10
8
解题思路:BIT,简单做个减法即可。
AC代码:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn=1e5+5;
 5 LL val[maxn],sum1[maxn],sum2[maxn];int n,q,a,b,c;
 6 int lowbit(int x){return x&-x;}
 7 void add(LL *sum,int x,LL val){
 8     for(int i=x;i<=n;i+=lowbit(i))
 9         sum[i]+=val;
10 }
11 LL query(LL *sum,int x){
12     LL mul=0;
13     for(int i=x;i>0;i-=lowbit(i))
14         mul+=sum[i];
15     return mul;
16 }
17 int main() {
18     while(~scanf("%d%d",&n,&q)){
19         memset(sum1,0,sizeof(sum1));
20         memset(sum2,0,sizeof(sum2));
21         for(int i=1;i<=n;++i){
22             scanf("%lld",&val[i]);
23             add(sum1,i,val[i]);
24             add(sum2,i,val[i]*(n-i+1));
25         }
26         while(q--){
27             scanf("%d%d%d",&a,&b,&c);
28             if(a==2){
29                 add(sum1,b,c-val[b]);
30                 add(sum2,b,(c-val[b])*(n-b+1));
31                 val[b]=c;
32             }
33             else printf("%lld\n",query(sum2,c)-query(sum2,b-1)-(n-b+1-(c-b+1))*(query(sum1,c)-query(sum1,b-1)));
34         }
35     }
36     return 0;
37 }

I. Characters with Hash

Mur loves hash algorithm, and he sometimes encrypt another one’s name, and call him with that encrypted value. For instance, he calls Kimura KMR, and calls Suzuki YJSNPI. One day he read a book about SHA-256, which can transit a string into just 256 bits. Mur thought that is really cool, and he came up with a new algorithm to do the similar work. The algorithm works this way: first we choose a single letter L as the seed, and for the input(you can regard the input as a string s, s[i] represents the i th character in the string)we calculates the value(|(int) L – s[i]|), and write down the number(keeping leading zero. The length of each answer equals to 2 because the string only contains letters and numbers). Numbers writes from left to right,finally transfer all digits into a single integer(without leading zero(s)). For instance, if we choose ‘z’ as the seed, the string “oMl” becomes “11 45 14”. It’s easy to find out that the algorithm cannot transfer any input string into the same length. Though in despair, Mur still wants to know the length of the answer the algorithm produces. Due to the silliness of Mur, he can even not figure out this, so you are assigned with the work to calculate the answer.

Input

First line a integer T, the number of test cases(T <= 10)
For each test case:
First line contains a integer N and a character z, (N <= 1000000)
Second line contains a string with length N. Problem makes sure that all characters referred in the problem are only letters.

Output

A single number which gives the answer.

样例输入

2
3 z
oMl
6 Y
YJSNPI

样例输出

6
10
解题思路:水~
AC代码:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=1e6+5;
 4 char str[maxn];int res[maxn];
 5 int getd(int x){
 6     int num=0;
 7     while(x){num++,x/=10;}
 8     return num;
 9 }
10 int main(){
11     int t,n,pos,st;char ch;
12     while(~scanf("%d",&t)){
13         while(t--){
14             scanf("%d %c",&n,&ch);
15             scanf("%s",str);st=pos=0;
16             for(int i=0;i<n;++i){
17                 int tmp=fabs((int)ch-str[i]);
18                 int dig=getd(tmp);
19                 if(dig==1)res[pos++]=0,res[pos++]=tmp;
20                 else res[pos++]=tmp/10,res[pos++]=tmp%10;
21             }
22             while(!res[st]&&st<pos)st++;
23             if(st==pos)puts("1");
24             else printf("%d\n",pos-st);
25         }
26     }
27     return 0;
28 }

 

posted @ 2018-09-09 20:01  霜雪千年  阅读(381)  评论(0编辑  收藏  举报