Codeforces Round #342 (Div. 2)

怒A三题、虽然有点水

A. Guest From the Past

题意:就说一个人去喝酒,有n块钱,塑料瓶装的就是a块钱一瓶,玻璃瓶装酒是b块钱一瓶,一个玻璃瓶又可以换c块钱,问最多能喝到多少瓶酒

思路:很经典的模拟问题,类那个猴子吃桃,多少核桃又可以换一个桃那种题,不过这个题目有个坑点,看代码把

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cmath>
 4 using namespace std;
 5 int main()
 6 {
 7     long long n,a,b,c;
 8     while(cin >> n >> a >> b >> c){
 9         long long maxn=n/a;
10         long long su=0;
11         long long k;
12         while(n>=b){
13             k=n/b;
14             n=n-k*b;
15             su+=k;
16             n=n+k*c;
17         }
18         su+=n/a;                //就是这个坑点,剩下的钱可能可以买几瓶塑料酒
19         if(maxn>su)    cout << maxn << endl;
20         else        cout << su << endl;
21     }
22 }

B. War of the Corporations

题意:给a串和b串和你问a串中有多少个b串

思路:典型的KMP字符串匹配问题

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<cstring>
 4 using namespace std;
 5 const int qq=1e5+50;
 6 char a[qq],b[qq],next[qq];
 7 long long tot;
 8 void get()
 9 {
10     int j,k;
11     next[0]=-1;j=0;k=-1;
12     while(j<strlen(b)-1){
13         if(k==-1||b[j]==b[k])
14             next[j++]=k++;
15         else
16             k=next[k];
17     }
18 }
19 void KMP()
20 {
21     int i,j;
22     i=j=0;
23     while(i<strlen(a)){
24         if(j==-1||a[i]==b[j]){
25             ++i;++j;
26         }
27         else
28             j=next[j];
29         if(j==strlen(b)){
30             ++tot;
31             j=0;
32         }
33     }
34 }
35 int main()
36 {
37     while(~scanf("%s%s",a,b)){
38         tot=0;
39         get();
40         KMP();
41         printf("%lld\n",tot);
42     }
43 }

C. K-special Tables

题意:给一个n和k的,要求第k列的和最大,n*n的矩阵,要求1到n*n所有数都出现,且每一行从左到右要求为递增

思路:找规律把、看样例比较代码就可以看到规律了

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<iostream>
 4 using namespace std;
 5 const int qq=500+50;
 6 int num[qq][qq];
 7 int main()
 8 {
 9     int n,k;
10     while(cin >> n >> k){
11         int sum=0;
12         int ans=1;
13         for(int i=0;i<n;++i)
14             for(int j=0;j<k-1;++j)
15                 num[i][j]=ans++;
16         for(int i=0;i<n;++i)
17             for(int j=k-1;j<n;++j)
18                 num[i][j]=ans++;
19         for(int i=0;i<n;++i)
20             sum+=num[i][k-1];
21         cout << sum << endl;
22         for(int j,i=0;i<n;++i){
23             for(j=0;j<n;++j)
24                 if(j==0)    cout << num[i][j];
25                 else        cout << " " << num[i][j];
26             cout << endl;
27         }
28     }
29 } 
时间: 2024-08-08 15:42:21

Codeforces Round #342 (Div. 2)的相关文章

Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)

传送门 Description A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000. This new devic

Codeforces Round #342 (Div. 2) C. K-special Tables(想法题)

传送门 Description People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among

Codeforces Round #342 (Div. 2) A. Guest From the Past(贪心)

传送门 Description Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated. Koly

Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)

传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much

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 Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd