2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

思路:

Exam

思路:水题

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int k;
  5. scanf("%d",&k);
  6. char s1[],s2[];
  7. scanf("%s%s",s1,s2);
  8. int same=;
  9. int n=strlen(s1);
  10. for(int i=;i<n;i++){
  11. same+=s1[i]==s2[i];
  12. }
  13. cout<<min(same,k)+min(n-same,n-k)<<endl;
  14. return ;
  15. }

Coprime Integers

思路:容斥

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 1e7 + ;
  25. LL g[N];
  26. LL solve(int a, int b) {
  27. if(a > b) swap(a, b);
  28. if(a == ) return ;
  29. for (int i = a; i >= ; i--) {
  30. g[i] = 1LL * (a/i) * (b/i);
  31. for (int j = i+i; j <= a; j += i) g[i] = g[i] - g[j];
  32. }
  33. return g[];
  34. }
  35. int main() {
  36. int a, b, c, d;
  37. scanf("%d %d %d %d", &a, &b, &c, &d);
  38. printf("%lld\n", solve(b, d) - solve(b, c-) - solve(a-, d) + solve(a-, c-));
  39. return ;
  40. }

Contest Setting

思路:dp

dp[i][j]表示前i种选j个的方案数

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int MOD = ;
  25. const int N = 1e3 + ;
  26. LL dp[N][N];
  27. int cnt[N], a[N], tot = ;
  28. map<int, int> mp;
  29. int main() {
  30. int n, k;
  31. scanf("%d %d", &n, &k);
  32. for (int i = ; i <= n; i++) {
  33. scanf("%d", &a[i]);
  34. if(mp.find(a[i]) == mp.end()) mp[a[i]] = ++tot, cnt[tot] = ;
  35. else cnt[mp[a[i]]] ++;
  36. }
  37. dp[][] = ;
  38. for (int i = ; i <= tot; i++) {
  39. for (int j = ; j <= k; j++) dp[i][j] = dp[i-][j];
  40. for (int j = ; j <= k; j++) dp[i][j] = (dp[i][j] + dp[i-][j-]*cnt[i]) % MOD;
  41. }
  42. printf("%lld\n", dp[tot][k]);
  43. return ;
  44. }

Count The Bits

思路:dp

dp[i][j][0]表示前i位构成的数中对k取模为j的数的个数

dp[i][j][1]表示前i位构成的数中对k取模为j的数中二进制中1的个数

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = , M = 1e3 + ;
  25. const int MOD = 1e9 + ;
  26. LL dp[N][M][];
  27. int main() {
  28. int k, b;
  29. scanf("%d %d", &k, &b);
  30. dp[][][] = ;
  31. dp[][][] = ;
  32. for (int i = ; i <= b; i++) {
  33. for (int j = ; j < k; j++) {
  34. (dp[i][(j*)%k][] += dp[i-][j][]) %= MOD;
  35. (dp[i][(j*+)%k][] += dp[i-][j][]) %= MOD;
  36.  
  37. (dp[i][(j*)%k][] += dp[i-][j][]) %= MOD;
  38. (dp[i][(j*+)%k][] += dp[i-][j][] + dp[i-][j][]) %= MOD;
  39. }
  40. }
  41. printf("%lld\n", dp[b][][]);
  42. return ;
  43. }

Cops And Roobers

Rectangles

Goat on a Rope

思路:求点到矩形的最近距离

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. double cal(double x1,double y1,double x2,double y2)
  4. {
  5. return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  6. }
  7. int main()
  8. {
  9. double x,y,x1,x2,y1,y2,ans=1e9;
  10. scanf("%lf%lf%lf%lf%lf%lf",&x,&y,&x1,&y1,&x2,&y2);
  11. if(x>=min(x1,x2)&&x<=max(x2,x1)) ans=min(abs(y1-y),abs(y2-y));
  12. else if(y>=min(y1,y2)&&y<=max(y1,y2)) ans=min(abs(x-x1),abs(x-x2));
  13. else ans=min(cal(x,y,x1,y1),min(cal(x,y,x2,y2),min(cal(x,y,x1,y2),cal(x,y,x2,y1))));
  14. printf("%.3f\n",ans);
  15. }

Repeating Goldbachs

思路:暴力

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 1e6 + ;
  25. int p[N], tot = ;
  26. bool not_p[N];
  27. void seive() {
  28. for (int i = ; i < N; i++) {
  29. if(!not_p[i]) {
  30. p[++tot] = i;
  31. }
  32. for (int j = ; j <= tot && p[j]*i < N; j++) {
  33. not_p[p[j]*i] = true;
  34. if(i % p[j] == ) break;
  35. }
  36. }
  37. }
  38. int main() {
  39. int x;
  40. scanf("%d", &x);
  41. seive();
  42. int ans = ;
  43. while(x >= ) {
  44. for(int i = ; i <= tot && p[i] <= x; i++) {
  45. if(!not_p[x-p[i]]) {
  46. x = x - p[i] - p[i];
  47. ans++;
  48. break;
  49. }
  50. }
  51. }
  52. printf("%d\n", ans);
  53. return ;
  54. }

Inversions

Time Limits

思路:水题

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = ;
  25. int t[N];
  26. int n, s;
  27. int main() {
  28. scanf("%d %d", &n, &s);
  29. for (int i = ; i <= n; i++) scanf("%d", &t[i]);
  30. sort(t+, t++n);
  31. printf("%d\n", (t[n]*s + ) / );
  32. return ;
  33. }

Knockout

Liars

思路:暴力

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 1e3 + ;
  25. pii a[N];
  26. int main() {
  27. int n;
  28. scanf("%d", &n);
  29. for (int i = ; i <= n; i++) scanf("%d %d", &a[i].fi, &a[i].se);
  30. int ans = -;
  31. for (int i = ; i <= n; i++) {
  32. int cnt = ;
  33. for (int j = ; j <= n; j++) {
  34. if(a[j].fi <= i && i <= a[j].se) cnt++;
  35. }
  36. if(cnt == i) ans = max(ans, i);
  37. }
  38. printf("%d\n", ans);
  39. return ;
  40. }

Mobilization

2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)的更多相关文章

  1. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

  2. Contest Setting 2018 ICPC Pacific Northwest Regional Contest dp

    题目:https://vj.69fa.cn/12703be72f729288b4cced17e2501850?v=1552995458 dp这个题目网上说是dp+离散化这个题目要对这些数字先处理然后进 ...

  3. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Alphabet Solved. 签. #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ scanf(); ...

  4. 2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) S Surf

    SurfNow that you've come to Florida and taken up surng, you love it! Of course, you've realized that ...

  5. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) 题解

    [题目链接] A - Alphabet 最长公共子序列.保留最长公共子序列,剩余的删除或者补足即可. #include <bits/stdc++.h> using namespace st ...

  6. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Exam Solved. 温暖的签. #include<bits/stdc++.h> using namespace std; ; int k; char str1[maxn], st ...

  7. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) K Tournament Wins

    题目链接:http://codeforces.com/gym/101201 /* * @Author: lyucheng * @Date: 2017-10-22 14:38:52 * @Last Mo ...

  8. 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

    A. Odd Palindrome 所有回文子串长度都是奇数等价于不存在长度为$2$的偶回文子串,即相邻两个字符都不同. #include<cstdio> #include<cstr ...

  9. 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) B - Enlarging Enthusiasm dp好题

    B - Enlarging Enthusiasm 感觉做到过好多的dp题都会和单调性结合在一起. 思路:dp[ s ][ pre ][ res ] 表示的是已选择了s,上一个是pre, 还有res 的 ...

随机推荐

  1. php简单使用shmop函数创建共享内存减少服务器负载

    在之前的一篇博客[了解一下共享内存的概念及优缺点]已经对共享内存的概念做了说明.下面就来简单使用共享内存(其实也可以用其他工具,比如redis) PHP做内存共享有两套接口.一个是shm,它实际上是变 ...

  2. bzoj1227 P2154 [SDOI2009]虔诚的墓主人

    P2154 [SDOI2009]虔诚的墓主人 组合数学+离散化+树状数组 先看题,结合样例分析,易得每个墓地的虔诚度=C(正左几棵,k)*C(正右几棵,k)*C(正上几棵,k)*C(正下几棵,k),如 ...

  3. ubuntu18.04 安装新版本openssl

    首先我们应该知道ubuntu18.04内置了1.1.0g版本的openssl: 使用下面的apt命令更新Ubuntu存储库并安装软件包编译的软件包依赖项: sudo apt update sudo a ...

  4. 20155201 网络攻防技术 实验八 Web基础

    20155201 网络攻防技术 实验八 Web基础 一.实践内容 Web前端HTML,能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. We ...

  5. bzoj 2733 永无乡 - 并查集 - 线段树

    永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示.某些岛之间由巨大的桥连接,通过桥可以从一个岛 到达另一个岛. ...

  6. 转载:索引与分片 plus

    [Python笔记]序列(一)索引.分片   Python包含6种内建序列:列表.元组.字符串.Unicode字符串.buffer对象.xrange对象.这些序列支持通用的操作: 索引 索引是从0开始 ...

  7. 16 级高代 II 思考题十的多种证明

    16 级高代 II 思考题十  设 $V$ 是数域 $\mathbb{K}$ 上的 $n$ 维线性空间, $\varphi$ 是 $V$ 上的线性变换, 证明: $\varphi$ 的极小多项式 $m ...

  8. CentOS6.8下安装Redis

    1.由于Redis是使用C语言开发的,安装时需要对Redis的源码进行编译,编译依赖gcc环境,如果没有gcc,需要先安装gcc: yum install gcc-c++ 2.安装完成后,进入Redi ...

  9. Python常用库之functools

    functools 是python2.5被引人的,一些工具函数放在此包里. python2.7中 python3.6中 import functools print(dir(functools)) [ ...

  10. android linux 休眠 深度睡眠 查看 方法 调试【转】

    本文转载自:https://blog.csdn.net/u011006622/article/details/72900552 在Android移动设备中,有时按下Power键(未接电源,USB)时, ...