Codeforces Round #392 (Div. 2)

A - Holiday Of Equality(water)

题意:一共给你N个数,让你向上补数值,使得最终所有数值都相等,输出最少花费。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int INF = 0x3f3f3f3f;
 5 const int maxn = 100 + 5;
 6
 7 int a[maxn];
 8
 9 int main()
10 {
11     int n;
12     scanf("%d", &n);
13     int maxx = -INF;
14     for(int i = 0; i <n; i++)
15     {
16         scanf("%d", &a[i]);
17         if(a[i] > maxx) maxx = a[i];
18     }
19     int sum = 0;
20     for(int i = 0; i < n; i++)
21     {
22         sum += maxx - a[i];
23     }
24     cout << sum << endl;
25     return 0;
26 }

B - Blown Garland(杂?)

题意:一共有四种颜色的灯RBYG,现在有!处表示这个位子的灯泡坏掉了,我们现在需要在!处放置四种颜色的灯泡,使得最终的序列,保证每连续的四个灯泡都具有四种不同的颜色。问我们需要添加多少个R,B,Y,G.保证答案唯一。

思路:神特么这题一开始卡住不知道怎么写好。然后抓着前四个点确定,则整串都确定的特点。。直接几个for一套暴力掉了,反正没多大。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int INF = 0x3f3f3f3f;
 5 const int maxn = 100 + 5;
 6
 7 char s[maxn], ss[maxn];
 8 int vis[10];
 9 int r,y,g,b;
10 char p[] = {‘R‘, ‘B‘, ‘Y‘, ‘G‘};
11
12 void solve(char ss[])
13 {
14     for(int i = 4; i < strlen(s); i++)
15     {
16         ss[i] = ss[i - 4];
17     }
18     int cntr = 0, cnty = 0, cntg = 0, cntb = 0;
19     for(int i = 0; i < strlen(s); i++)
20     {
21         if(s[i] != ‘!‘)
22         {
23             if(s[i] != ss[i])
24             {
25                 return;
26             }
27         }
28         else
29         {
30             if(ss[i] == ‘R‘)    cntr++;
31             else if(ss[i] == ‘Y‘)   cnty ++;
32             else if(ss[i] == ‘G‘)   cntg++;
33             else if(ss[i] == ‘B‘)   cntb++;
34         }
35     }
36     r = cntr, y = cnty, g = cntg, b = cntb;
37 }
38
39 int main()
40 {
41     scanf("%s", s);
42     r = 0, b = 0, y = 0, g = 0;
43     for(int i = 0; i < 4; i++)
44     {
45         for(int j = 0; j < 4; j++)
46         {
47             for(int k = 0; k < 4; k++)
48             {
49                 for(int l = 0; l < 4; l++)
50                 {
51                     ss[0] = p[i], ss[1] = p[j], ss[2] = p[k], ss[3] = p[l];
52                     solve(ss);
53                 }
54             }
55         }
56     }
57     cout << r << " " << b << " " <<  y << " " << g << endl;
58     return 0;
59 }

看了看别人的代码,智商被碾压了。

撒比嘛你是,任意四个点确定,则整个序列确定,那么对于i%4来说,余数相同的位置的颜色必然相同啊。= =。╮(╯▽╰)╭真是撒比lity。

 1 #include <iostream>
 2 using namespace std;
 3 typedef long long ll;
 4 ll n,mx,x,sum,a[222],b[4];
 5 string s;
 6 int main()
 7 {
 8     cin>>s;
 9     n=s.size();
10     for(ll i=0;i<n;i++)
11         if(s[i]!=‘!‘)
12             a[s[i]]=i%4;
13     for(ll i=0;i<n;i++)
14         if(s[i]==‘!‘)
15             b[i%4]++;
16     cout<<b[a[‘R‘]]<<" "<<b[a[‘B‘]]<<" "<<b[a[‘Y‘]]<<" "<<b[a[‘G‘]];
17 }

C - Unfair Poll(数学)

题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点,当点完第n列的名之后,接着点第n-1列的名。以此类推,就是从列上来看的话:1,2,3,4,……,n,n-1,n-2,……,1 ,2,……。这样的顺序点名。老师上课总共点k次名,问该课堂最多可以点同一个同学多少次,最少可以点同一个同学多少次,点了位置为(x,y)的同学多少次名。

思路:记住!!!不要迷信推公式!!!在复杂度允许的时候!!!加一点适当的模拟会好很多啊!!!不容易错啊!!!比如算求余以后的多余的量的时候!!!公式不小心推错了啊啊啊啊啊啊!!!!

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int INF = 0x3f3f3f3f;
 5 const int maxn = 100 + 5;
 6
 7 LL n, m, k, x, y;
 8
 9 int main()
10 {
11     LL maxx = 0, minn = INF, special = 0;
12     cin >> n >> m >> k >> x >> y;
13     if(n == 1)
14     {
15         LL times = k / m;
16         LL mod = k % m;
17         maxx = times + (mod != 0);
18         minn = times;
19         special = times + (y <= mod);
20     }
21     else if(n == 2)
22     {
23         LL times = k / (2 * m);
24         LL mod = k % (2 * m);
25         maxx = times + (mod != 0);
26         minn = times;
27         special = times + ((x - 1) * m + y <= mod);
28     }
29     else
30     {
31         if(k <= n * m)
32         {
33             maxx = 1;
34             minn = ((n * m) == k);
35             if((x - 1) * m + y <= k)
36             {
37                 special = 1;
38             }
39         }
40         else
41         {
42             LL times = k / ((2 * n - 2) * m);
43             LL mod = k % ((2 * n - 2) * m);
44             if(mod > n * m)
45             {
46                 minn = times + 1;
47                 maxx =  2 * times + 2;
48                 if(x == 1 || x == n)
49                 {
50                     special = times + 1;
51                 }
52                 else
53                 {
54                     special = times * 2 + 1 + (( (n - 1 - x) * m + y ) <= (mod - n * m));
55                 }
56             }
57             else
58             {
59                 minn = times + (mod == (n * m));
60                 maxx = 2 * times + (mod > m);
61                 if(x == 1 || x == n)
62                 {
63                     special = times +( ( (x - 1) * m + y ) <= (mod) );
64                 }
65                 else
66                 {
67                     special = times * 2 + (( (x - 1) * m + y ) <= (mod));
68                 }
69             }
70         }
71     }
72     cout << maxx << " " << minn << " " << special << endl;
73     return 0;
74 }

体会一下吧,大概就是可以用这种模拟的感觉。数学+模拟的感觉,比直接公式的容错率高一些。

 1 int main(void)
 2 {
 3     int i, j;
 4     cin>>n>>m>>k>>x>>y;
 5     if(n==1)
 6     {
 7         for(i=1 ; i<=n ; i++)
 8         {
 9             for(j=1 ; j<=m ; j++)
10             {
11                 val[i][j]+=k/m;
12             }
13         }
14         k%=m;
15         for(i=1 ; i<=n ; i++)
16         {
17             for(j=1 ; j<=k ; j++)
18             {
19                 val[i][j]++;
20             }
21         }
22     }
23     else
24     {
25         for(i=1 ; i<=n ; i++)
26         {
27             for(j=1 ; j<=m ; j++)
28             {
29                 val[i][j]+=k/((2*n-2)*m);
30                 if(i!=1 && i!=n)
31                 {
32                     val[i][j]+=k/((2*n-2)*m);
33                 }
34             }
35         }
36         k=k%((2*n-2)*m);
37         for(i=1 ; i<=n ; i++)
38         {
39             for(j=1 ; j<=m ; j++)
40             {
41                 if(k>0)
42                 {
43                     val[i][j]++;
44                     k--;
45                 }
46             }
47         }
48         for(i=n-1 ; i>=1 ; i--)
49         {
50             for(j=1 ; j<=m ; j++)
51             {
52                 if(k>0)
53                 {
54                     val[i][j]++;
55                     k--;
56                 }
57             }
58         }
59     }
60     for(i=1 ; i<=n ; i++)
61     {
62         for(j=1 ; j<=m ; j++)
63         {
64             ansf=max(ansf,val[i][j]);
65             anss=min(anss,val[i][j]);
66         }
67     }
68     cout<<ansf<<" "<<anss<<" "<<val[x][y];
69 }

D - Ability To Convert

时间: 2024-08-27 19:23:50

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

Codeforces Round #392 (Div. 2) F. Geometrical Progression

原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output For given n, l and r find the number of distinct geometrical pro

Codeforces Round #392 (div.2) E:Broken Tree

orz一开始想不画图做这个题(然后脑袋就炸了,思维能力有待提高) 我的做法是动态规划+贪心+构造 首先把题目给的树变成一个可行的情况,同时weight最小 这个可以通过动态规划解决 dp[x]表示以x为结点的子树,它的最小weight是多少 接着我们就只需要考虑每条边增加多少就可以了,这里可以用贪心的做法 ddfs(int x, int fa, int v) 这里v是表示给x结点最大多少增量,然后慢慢加就可以,返回没用掉的增量 其实这个做法有点奇怪,应该有更简便的做法(我觉得可以直接贪心做) #

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

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f