2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

http://codeforces.com/contest/1070

A

给你一个d和s,求一个最小的数,使的能整除d,并且每位数的和为s。

如果确定了某n位数取模d的值,那么再计算同样的n位数,取模d也是相同的值时,就多此一举了。比如10%2 == 0  20%2 == 0  同样是两位数,取模2都是等于0。所以取最小的就可以了。

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N = 1e3+10;
 5 struct Nod{
 6     int d, s;
 7     string str;
 8 };
 9 bool vis[N/2][N*5];
10 int d, s;
11 void bfs() {
12     queue<Nod> que;
13     que.push({0,0,""});
14     vis[0][0] = 1;
15     while(que.size()) {
16         Nod nod = que.front();
17         que.pop();
18         if(nod.s > s) continue;
19         if(nod.d == 0 && nod.s == s) {
20             cout << nod.str << endl;
21             return;
22         }
23         for(int i = 0; i < 10; i ++) {
24             int dd = (nod.d*10+i)%d;
25             int ss = nod.s + i;
26             if(!vis[dd][ss]) {
27                 vis[dd][ss] = 1;
28                 que.push({dd,ss,nod.str+char(i+‘0‘)});
29             }
30         }
31     }
32     cout << -1 << endl;
33 }
34
35 int main() {
36     cin >> d >> s;
37     bfs();
38     return 0;
39 }

D

扔垃圾问题,当天的垃圾可以今天扔也可以明天扔,但最后一天的垃圾必须当天扔。每k个垃圾要用一个垃圾袋。求用垃圾袋最小的数量。

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N = 1e5+10;
 5
 6 int main() {
 7     ll n, k;
 8     cin >> n >> k;
 9     ll ans = 0, x, pre = 0;
10     for(int i = 1; i <= n; i ++) {
11         cin >> x;
12         if(i == n) {
13             ans += (x+pre+k-1)/k;
14             break;
15         }
16         if(pre > 0) {
17             ans ++;
18             x = max(0LL,x - (k-pre));
19         }
20         ans += x/k;
21         pre = x-x/k*k;
22     }
23     printf("%lld\n",ans);
24     return 0;
25 }

F

有n个观众,每个人有两个由‘0‘和‘1‘组成的字符串,还有一个值。从中选取一些观众,使的第一个1的数量和第二个1的数量都不小于一半。

贪心问题,两个1的全部都选上,然后再选取写与01和10组成的,按价值最大的取,最后在去00或01或10 数量不超过11的数量就行。

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N = 4e5+10;
 5 int a[N], b[N], c[N], d[N];
 6 bool cmp(int x, int y) {
 7     return x > y;
 8 }
 9 int main() {
10     int n, x;
11     cin >> n;
12     string s;
13     for(int i = 1; i <= n; i ++) {
14         cin >> s >> x;
15         if(s == "11")  a[++a[0]] = x;
16         else if(s == "10") b[++b[0]] = x;
17         else if(s == "01") c[++c[0]] = x;
18         else d[++d[0]] = x;
19     }
20     sort(a+1,a+1+a[0],cmp);
21     sort(b+1,b+1+b[0],cmp);
22     sort(c+1,c+1+c[0],cmp);
23     ll ans = 0;
24     for(int i = 1; i <= a[0]; i ++) ans += 1LL*a[i];
25     for(int i = 1; i <= min(b[0],c[0]); i ++) ans += 1LL*(b[i]+c[i]);
26     for(int i = min(b[0],c[0])+1; i <= max(b[0],c[0]); i ++) d[++d[0]] = max(b[i],c[i]);
27     sort(d+1,d+1+d[0],cmp);
28     for(int i = 1; i <= min(a[0],d[0]); i ++) ans += 1LL*d[i];
29     printf("%lld\n",ans);
30     return 0;
31 }

H

有n个字符串和q个询问,每次询问有一个字符串s,问这个字符串s是n个字符串中的多少个的子串。

由于n个字符串最多8个字符,它的子串数量最多32个。就预处理一下很好就算出来了。

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N = 1e4+10;
 5 map<string,int> mp1, mp2;
 6 set<string> st;
 7 string s[N];
 8 int main() {
 9     ios::sync_with_stdio(false);
10     cin.tie(0);
11     cout.tie(0);
12     int n, q;
13     cin >> n;
14     string ss;
15     for(int i = 1; i <= n; i ++) {
16         cin >> s[i];
17         st.clear();
18         int len = s[i].length();
19         for(int j = 0; j < len; j ++) {
20             for(int k = 1; k <= len-j; k ++) {
21                 ss = s[i].substr(j,k);
22                 st.insert(ss);
23             }
24         }
25         for(auto tmp : st) {
26             mp1[tmp]++;
27             mp2[tmp] = i;
28             //cout << tmp << endl;
29         }
30     }
31     cin >> q;
32     while(q--) {
33         cin >> ss;
34         if(mp1.count(ss)) {
35             cout << mp1[ss] << ‘ ‘ << s[mp2[ss]] << endl;;
36         } else cout << "0 -\n";
37     }
38     return 0;
39 }

k

有n个数,为是否可以分成k份,使的每一份的和都相同。

签到题。

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N = 1e5+10;
 5 int a[N], n, k, sum = 0;
 6
 7 int find(int x) {
 8     int l = 1, r = n;
 9     while(l <= r) {
10         int m = (l +r)>>1;
11         if(a[m] == x) return m;
12         if(a[m] < x) l = m+1;
13         else r = m - 1;
14     }
15     return -1;
16 }
17
18 int main() {
19     cin >> n >> k;
20     for(int i = 1; i <= n; i ++) {
21         cin >> a[i];
22         a[i] += a[i-1];
23     }
24     if(a[n]%k != 0) return 0*printf("No\n");
25     int num = a[n]/k;
26     vector<int> v;
27     for(int i = 1; i <= k; i ++) {
28         int id = find(i*num);
29         if(id == -1) return 0*printf("No\n");
30         v.push_back(id);
31     }
32     printf("Yes\n%d",v[0]);
33     for(int i = 1; i < v.size(); i ++) {
34         printf(" %d",v[i]-v[i-1]);
35     }
36     return 0;
37 }

原文地址:https://www.cnblogs.com/xingkongyihao/p/9838275.html

时间: 2024-08-29 11:59:14

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)的相关文章

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) 体验记

原文链接https://www.cnblogs.com/zhouzhendong/p/CF1070.html 比赛网址:http://codeforces.com/contest/1070 感受 本来只打算玩玩的. 结果玩的海星. 我做 A 题的时候可能比较浮躁吧,各种傻错误,爆了 7 个罚时. 我 A 还没过,cly 神仙已经把 CDK 切光了. 4点半过一会儿,各自回家.cly 要剃头,就咕咕咕了.我本来也要剃的,后来临时决定先打题. 然后过了 A ,顺手切掉了 H 和 F ,开了 E ,猜

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Partial Solution

从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Garbage Disposal Problem E Getting Deals Done Problem F Debate Problem G Monsters and Potions Problem H BerOS File Suggestion Problem I Privatization of

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$<d, s>$ 表示当前状态模d的值,以及每一位加起来的值 跑最短路,从$<0, 0>  跑到 <0, s>$ 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 const int maxn = 1e5 +

2018-2019 ICPC, NEERC, Southern Subregional Contest

目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Cloud Computing(线段树) D.Garbage Disposal(模拟) E.Getting Deals Done(二分) F.Debate(贪心) H.BerOS File Suggestion(后缀自动机) I.Privatization of Roads in Berland(网络流)

模拟赛小结:2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest

2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest 2019年10月11日 15:30-20:30(Solved 6,Penalty 740) 国庆咸鱼十来天,回来又过了快一个星期,终于和队友约上了模拟赛.(周三拖周四,因为队(fei)友(zhai)们要跑1000米,又拖到周五QAQ) I:00:04.开场翻翻题目,机智如我很快找到一个贪心. D:00:36.看了看现场榜,有人交D.F和M,lh同学已经开F去了,xk同学说他M思路差不多

D. Dog Show 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)

http://codeforces.com/contest/847/problem/D 巧妙的贪心 仔细琢磨... 像凸包里的处理 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #includ

NEERC Southern Subregional 2012

NEERC Southern Subregional 2012 Problem B. Chess Championship 题目描述:有两个序列\(a, b\),两个序列都有\(n\)个数,并且这\(2n\)个数两两不同,现在要将这两个序列里的数两两配对,组成\(n\)个数对,要求数对中\(a\)的数比\(b\)的数大的数对个数要比其它的多\(m\)个.问方案数. solution 将这\(2n\)个数从小到大排,预处理出前\(i\)个数中\(a, b\)的个数\(suma, sumb\), \

2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest PART (7/10)

\[2013-2014\ ACM-ICPC,\ NEERC,\ Eastern\ Subregional\ Contest\] \(A.Podracing\) \(B.The\ battle\ near\ the\ swamp\) 签到 //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace std; function<void(

ACM ICPC 2011–2012, NEERC, Northern Subregional Contest J. John’s Inversions(合并排序求逆序数对数)

题目链接:http://codeforces.com/gym/100609/attachments 题目大意:有n张牌,每张牌有红色和蓝色两面,两面分别写了一些数字,同种颜色的任意两个数字若排在前面的数字比排在后面的数字大就叫做一对逆序数.求怎样排序得到的逆序数对最少. 解题思路:其中一种颜色的数字是顺序且这种颜色数字相同时对应的另一种颜色的数字是顺序时得到的逆序数对数最少.难点在于求逆序数对数.因为数量很大O(n^2)复杂度不能满足,这里根据合并排序的原理求解每个数字前面有多少个比它大的数字,