Codeforces#355

大小号刷题,大号,被查重,悲剧,最后小号过了3题

A题:

分析:大于h的+2,小于等于h的+1

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 const int maxn=202;
15 int a[maxn];
16 int n,h;
17 int main()
18 {
19     while(cin>>n>>h)
20     {
21         long long sum=0;
22         for(int i=0;i<n;i++){
23             int x;
24             scanf("%d",&x);
25             if(x>h)
26                 sum+=2;
27             else
28                 sum+=1;
29         }
30         cout<<sum<<endl;
31     }
32     return 0;
33 }

B题:

题意:有n个长度分别为a1,a2.....an的木棒,每次可以削掉长度为k的,放入机器的最大长度不能大于h,一根接着一根地放入,问怎么才能用最少的次数

分析:看清题意发现是水题,一根接着一根放入,则我们判断一下上一根剩余的加上下一根的长度是否大于h,若大于,则只把剩余部分放入机器,否则把剩余部分和下一根一起放入机器

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 const int maxn=100010;
15 int  a[maxn];
16 int k,n,h;
17 int main()
18 {
19     while(cin>>n>>h>>k)
20     {
21         memset(a,0,sizeof(a));
22         for(int i=0;i<n;i++)
23             scanf("%d",&a[i]);
24         int t,f;
25         long long cnt=0;
26         for(int i=0;i<n;i++){
27             t=a[i]/k; //需要几刀
28             f=a[i]%k; //切完之后当前这段还剩多少
29             cnt+=t;
30             if(a[i+1]+f>h){  //不能切分
31                 cnt++;
32             }else{  //可以切分
33                 a[i+1]+=f;
34             }
35         }
36         if(f) cnt++;
37         cout<<cnt<<endl;
38     }
39     return 0;
40 }

C题:

题意:一个字符串里面的字符分别代表不同的数,字符串的每个数是由两个不同的数按位&得到的,问这样的组合最多有多少个

分析:若是0,则有0&0,1&0,0&1,3种,若是1只有1&1这1种,因此就是统计每个数的二进制有多少个0即可

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 const int mod=1000000007;
15 const int maxn=100010;
16 char str[maxn];
17 long long num[maxn];
18 long long  solve(char s ){
19     long long x;
20     if(s>=‘0‘&&s<=‘9‘)
21         x=s-‘0‘;
22     else if(s>=‘A‘&&s<=‘Z‘)
23         x=s-‘A‘+10;
24     else if(s>=‘a‘&&s<=‘z‘)
25         x=s-‘a‘+36;
26     else if(s==‘-‘)
27         x=62;
28     else
29         x=63;
30     return x;
31 }
32 int main()
33 {
34
35     scanf("%s",str);
36     int n=strlen(str);
37     long long ans=1;
38     for(int i=0;i<n;i++){
39         long long x=solve(str[i]);
40         for(int j=0;j<6;j++){
41             if((x&(1<<j))==0)
42                 ans=ans*3%mod;
43         }
44     }
45     cout<<ans<<endl;
46     return 0;
47 }

时间: 2024-08-29 15:13:27

Codeforces#355的相关文章

Codeforces Round #355 (Div. 2) C

Description While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s 

Codeforces Round #355 (Div. 2) Vanya and Treasure

这是一道很显然的DP题目,状态转移在题目中也很直接,就是从k-1到k,然而如果count[k-1]*cnt[k],那么时间复杂度就会很大,本来的复杂度应该是O(p*n*n*m*m),用DP的话会很TLE,看了大牛的解释后,是在p<sqrt(mn)时候用DP,之后如果p>sqrt(nm)的话就用BFS,这样用均摊分析可以计算其时间复杂度(后边我打算写一篇关于均摊分析的博文). #include <iostream> #include <cstdio> #include &

Codeforces Round #355 (Div. 2) Vanya and Label

这道题很注重转化,其实质其实是将字符串每个字符转换成对应的数字后,按照6位进行二进制转化,然后统计0出现的次数,0&1=0,1&0=1,0&0=0,有些人用了快速幂,实际上这完全没有必要,但是一定要用long long. #include <iostream> #include <cstdio> #include <string> using namespace std; const long long MOD=1e9+7; string s;

Codeforces Round #355 (Div. 2)

A 弯腰 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<queue> 5 #include<stack> 6 #include<algorithm> 7 using namespace std; 8 #define clc(a,b) memset(a,b,sizeof(a)) 9 #define inf 0x3f3f3f3f 10 cons

Codeforces Round #355 (Div. 2) D. Vanya and Treasure 分治暴力

D. Vanya and Treasure Vanya is in the palace that can be represented as a grid n?×?m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x?≤?p?-?1 contains a key

Codeforces Round #355 (Div. 2) B

Description Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remai

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

codeforces:Prefix Sums

题目大意: 给出一个函数P,P接受一个数组A作为参数,并返回一个新的数组B,且B.length = A.length + 1,B[i] = SUM(A[0], ..., A[i]).有一个无穷数组序列A[0], A[1], ... 满足A[i]=P(A[i-1]),其中i为任意自然数.对于输入k和A[0],求一个最小的下标t,使得A[t]中包含不小于k的数值. 其中A[0].length <= 2e5, k <= 1e18,且A[0]中至少有两个正整数. 数学向的题目.本来以为是个找规律的题目

codeforces:Helga Hufflepuff&#39;s Cup

题目大意:有一个包含n个顶点的无向无环连通图G,图中每个顶点都允许有一个值type,type的范围是1~m.有一个特殊值k,若一个顶点被赋值为k,则所有与之相邻的顶点只能被赋小于k的值.最多有x个顶点被赋值为k.求问有多少种不同的赋值方案. 这是一道树形DP的题目.由于是无环无向连通图,因此可以任选一个顶点R作为根结点,从而构造一颗树TREE.为每个顶点N维护一个属性maybe[3][x+1].其中maybe[0][i]表示当N被赋小于k的值时,N及其所有后代结点总共出现i个被赋值为k的结点的总