BestCoder Round #81 (div.2)

HDU:5670~5764

A题: 是一个3进制计数;

 1 #include <bits/stdc++.h>
 2
 3 using namespace std;
 4
 5 int a[100000];
 6
 7 int calc(long long n) {
 8     int i=0;
 9     while(n) {
10         a[i++] = n%3;
11         n/=3;
12     }
13     return i;
14 }
15
16 int main()
17 {
18     int t;
19     cin>>t;
20     while(t--) {
21         memset(a,0,sizeof(0));
22         int m;  //长度
23         long long n;
24         cin>>m>>n;
25         int k = calc(n);
26         for(int i=0;i<m-k;i++) {
27             putchar(‘R‘);
28         }
29         for(int i=min(k-1,m-1);i>=0;i--) {
30             if(a[i]==0)
31                 putchar(‘R‘);
32             else if(a[i]==1)
33                 putchar(‘G‘);
34             else putchar(‘B‘);
35         }
36         puts("");
37     }
38     return 0;
39 }

B题:矩阵操作,可以线段树,有更好的办法,就是现在的某一行是原来的哪一行记录下来;

 1 #include <bits/stdc++.h>
 2
 3 using namespace std;
 4
 5 const int maxn = 1005;
 6 int maps[maxn][maxn];
 7
 8 int r[maxn];    //当前的第i 行,是原来的r[i]
 9 int c[maxn];
10 int addr[maxn]; //当前的第i 行,上面加了addr[i]
11 int addc[maxn];
12
13 int main()
14 {
15     int t;
16     scanf("%d",&t);
17     while(t--) {
18         memset(addr,0,sizeof(addr));
19         memset(addc,0,sizeof(addc));
20
21         int n,m;
22         int q;
23         scanf("%d%d%d",&n,&m,&q);
24         for(int i=0;i<n;i++)
25             for(int j=0;j<m;j++)
26                 scanf("%d",&maps[i][j]);
27
28         for(int i=0;i<n;i++)
29             r[i] = i;
30         for(int i=0;i<m;i++)
31             c[i] = i;
32
33         int op,x,y;
34         while(q--) {
35             scanf("%d%d%d",&op,&x,&y);
36             if(op==1)
37             {
38                 x--;y--;
39                 swap(r[x],r[y]);
40                 swap(addr[x],addr[y]);
41             }
42             if(op==2) {
43                 x--;y--;
44                 swap(c[x],c[y]);
45                 swap(addc[x],addc[y]);
46             }
47             if(op==3) {
48                 x--;
49                 addr[x]+=y;
50             }
51             if(op==4) {
52                 x--;
53                 addc[x]+=y;
54             }
55         }
56
57         for(int i=0;i<n;i++) {
58             for(int j=0;j<m;j++) {
59                 if(j==m-1)
60                     printf("%d",maps[r[i]][c[j]]+addr[i]+addc[j]);
61                 else
62                     printf("%d ",maps[r[i]][c[j]]+addr[i]+addc[j]);
63             }
64             puts("");
65         }
66     }
67     return 0;
68 }

C题:一个字符串,仅有小写字母,求有多少个子串,至少K个不同的字母;

尺取,最好是hash,map,set可能会超时

 1 #include <bits/stdc++.h>
 2
 3 using namespace std;
 4
 5 const int maxn = 1000000+5;
 6
 7 char str[maxn];
 8 int vis[300];
 9
10 int main()
11 {
12     int t;
13     cin>>t;
14     while(t--) {
15         int k;
16         scanf("%s%d",str+1,&k);
17         int n = strlen(str+1);
18         memset(vis,0,sizeof(vis));
19         int r=0;
20         int cnt=0;
21         long long ans = 0;
22         for(int l=1;l<=n;l++) {
23             while(r<n&&cnt<k) {
24                 ++r;
25                 if(++vis[str[r]]==1)
26                     cnt++;
27             }
28             if(cnt>=k)
29                 ans +=n-r+1;
30             if(--vis[str[l]]==0)
31                 --cnt;
32         }
33         cout<<ans<<endl;
34     }
35     return 0;
36 }

D题:  n秒后,回到原点,有多少不同的路径;

枚举向右走了几步;

公式出来了,大组合数用到乘法逆元,求卡特兰数,在CSUFTOJ中有一个出栈序列的问题,i 步有多少种出栈方式;(代码还没写)

时间: 2024-12-12 16:22:08

BestCoder Round #81 (div.2)的相关文章

HDU 5671 Matrix (BestCoder Round #81 (div.2) 1002)

传送门 Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 311    Accepted Submission(s): 142 Problem Description There is a matrix M that has n rows and m columns (1≤n≤1000,1≤m≤1000).Then we

BestCoder Round #81 (div.1)A

水题...就是n的三进制后m位 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<iostream> 5 #include<queue> 6 #include<stack> 7 #include<cmath> 8 #include<algorithm> 9 #include<malloc.h> 10 using

BestCoder Round #81 (div.2) B Matrix

B题...水题,记录当前行是由原矩阵哪行变来的. 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<iostream> 5 #include<queue> 6 #include<stack> 7 #include<cmath> 8 #include<algorithm> 9 #include<malloc.h>

BestCoder Round #81 (div.2)C String

总体思路好想,就是在找K个不同字母的时候,卡时间. 看了大神代码,发现goto的!!!!998ms 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<iostream> 5 #include<queue> 6 #include<stack> 7 #include<cmath> 8 #include<algorithm> 9

【BestCoder Round #81 (div.2)】【HDU5670&amp;5671&amp;5672】题意&题解&代码(C++)

第一次bc做了3道题,虽然最后一道题是听了别人的思路,果然我还是太弱... div2t1(hdu5670): 题意: 有一个机器,它有 m(2≤m≤30) 个彩灯和一个按钮.每按下按钮时,最右边的彩灯会发生一次变换.变换为: 如果当前状态为红色,它将变成绿色: 2.如果当前状态为绿色,它将变成蓝色: 3.如果当前状态为蓝色,它将变成红色,并且它左边的彩灯(如果存在)也会发生一次变换. 初始状态下所有的灯都是红色的. 询问按下按钮 n(1≤n<2^63) 次以后各个彩灯的颜色. 题解: 很容易观察

计算几何(水)BestCoder Round #50 (div.2) 1002 Run

题目传送门 1 /* 2 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 3 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-8 19:54:14 8 * File Name :B.cpp 9 ************

hdu5418 BestCoder Round #52 (div.2) Victor and World ( floyd+状压dp)

Problem Description After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fly around the world. There are n countries on the earth, which are numbered from 1 to

BestCoder Round #11 (Div. 2) 前三题题解

题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 216    Accepted Submission(s): 166 Problem De

BestCoder Round #11 (Div. 2) 题解

HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 302    Accepted Submission(s): 229 Problem Description Bob and Alice got separated in the Square, they agreed that if they