Codeforces Beta Round #65 (Div. 2)

http://codeforces.com/contest/71

A

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. int main(){
  16. #ifndef ONLINE_JUDGE
  17. // freopen("input.txt","r",stdin);
  18. #endif
  19. std::ios::sync_with_stdio(false);
  20. int n;
  21. string str;
  22. cin>>n;
  23. rep(i,,n){
  24. cin>>str;
  25. if(str.length()<=){
  26. cout<<str<<endl;
  27. }
  28. else{
  29. cout<<str[];
  30. cout<<str.length()-;
  31. cout<<str[str.length()-]<<endl;
  32. }
  33. }
  34. }

B

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. int main(){
  16. #ifndef ONLINE_JUDGE
  17. // freopen("input.txt","r",stdin);
  18. #endif
  19. std::ios::sync_with_stdio(false);
  20. int n,k,t;
  21. cin>>n>>k>>t;
  22. int sum=t*n*k/;
  23. int tmp=sum/k;
  24. for(int i=;i<tmp;i++) cout<<k<<" ";
  25. if(tmp<n){
  26. int p=sum-tmp*k;
  27. cout<<p;
  28. for(int i=;i<n-tmp-;i++) cout<<" "<<;
  29. }
  30. }

C

模拟

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. int a[];
  16. int n;
  17.  
  18. int main(){
  19. #ifndef ONLINE_JUDGE
  20. // freopen("input.txt","r",stdin);
  21. #endif
  22. std::ios::sync_with_stdio(false);
  23. cin>>n;
  24. for(int i=;i<n;i++)cin>>a[i];
  25. int flag=;
  26. for(int i=;i<=n/;i++)
  27. if(n%i==)
  28. {
  29. for(int j=;j<i;j++)
  30. {
  31. flag=;
  32. for(int k=j;k<n;k+=i)
  33. flag&=a[k];
  34. if(flag)
  35. {
  36. cout<<"YES"<<endl;
  37. return ;
  38. }
  39. }
  40. }
  41. cout<<"NO"<<endl;
  42. }

D

大模拟

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. string A[][];
  16.  
  17. bool check1(int r, int c) {
  18. set <char> S;
  19.  
  20. int cnt = ;
  21.  
  22. for (int i = r; i <= r+; i++)
  23. for (int j = c; j <= c+; j++)
  24. if (A[i][j] == "J1" ||
  25. A[i][j] == "J2") {
  26.  
  27. cnt++;
  28. }
  29. else
  30. S.insert(A[i][j][]);
  31.  
  32. return ( (S.size() + cnt) == );
  33. }
  34.  
  35. bool check2(int r1, int c1, int r2, int c2) {
  36. for (int i = r1; i <= r1+; i++)
  37. for (int j = c1; j <= c1+; j++)
  38. if (r2 <= i && i <= r2+ &&
  39. c2 <= j && j <= c2+) {
  40.  
  41. return false;
  42. }
  43.  
  44. return true;
  45. }
  46.  
  47. bool check3(int r, int c) {
  48. set <char> S;
  49.  
  50. for (int i = r; i <= r+; i++)
  51. for (int j = c; j <= c+; j++)
  52. S.insert(A[i][j][]);
  53.  
  54. return ( S.size() == );
  55. }
  56.  
  57. int main(){
  58. #ifndef ONLINE_JUDGE
  59. // freopen("input.txt","r",stdin);
  60. #endif
  61. std::ios::sync_with_stdio(false);
  62. int n, m;
  63. cin >> n >> m;
  64.  
  65. string tmpRank[] = {"", "", "", "", "", "", "", "", "T", "J", "Q", "K", "A"};
  66. string tmpSuit[] = {"C", "D", "H", "S"};
  67. set <string> Pack;
  68. for (int i = ; i < ; i++)
  69. for (int j = ; j < ; j++)
  70. Pack.insert(tmpRank[i] + tmpSuit[j]);
  71. bool isThereJ1 = false;
  72. int J1r;
  73. int J1c;
  74. bool isThereJ2 = false;
  75. int J2r;
  76. int J2c;
  77. for (int i = ; i <= n; i++)
  78. for (int j = ; j <= m; j++) {
  79. cin >> A[i][j];
  80. if (A[i][j] == "J1") {
  81. isThereJ1 = true;
  82. J1r = i;
  83. J1c = j;
  84.  
  85. continue;
  86. }
  87. if (A[i][j] == "J2") {
  88. isThereJ2 = true;
  89. J2r = i;
  90. J2c = j;
  91.  
  92. continue;
  93. }
  94. Pack.erase(Pack.find(A[i][j]));
  95. }
  96.  
  97. vector <pair <int, int>> V;
  98.  
  99. for (int r = ; r <= n-; r++)
  100. for (int c = ; c <= m-; c++)
  101. if (check1(r, c))
  102. V.push_back(make_pair(r, c));
  103.  
  104. for (int i = ; i < V.size(); i++)
  105. for (int j = ; j < V.size(); j++) {
  106. if (i == j)
  107. continue;
  108. int r1 = V[i].first;
  109. int c1 = V[i].second;
  110. int r2 = V[j].first;
  111. int c2 = V[j].second;
  112. if (check2(r1, c1, r2, c2)) {
  113. if (isThereJ1 && isThereJ2) {
  114. for (set <string>::iterator it1 = Pack.begin(); it1 != Pack.end(); it1++)
  115. for (set <string>::iterator it2 = Pack.begin(); it2 != Pack.end(); it2++) {
  116. if (it1 == it2)
  117. continue;
  118. A[J1r][J1c] = *it1;
  119. A[J2r][J2c] = *it2;
  120. if (check3(r1, c1) &&
  121. check3(r2, c2)) {
  122. cout << "Solution exists." << endl;
  123. cout << "Replace J1 with " << (*it1) << " and J2 with " << (*it2) << "." << endl;
  124. cout << "Put the first square to (" << r1 << ", " << c1 << ")." << endl;
  125. cout << "Put the second square to (" << r2 << ", " << c2 << ").";
  126. return ;
  127. }
  128. A[J1r][J1c] = "J1";
  129. A[J2r][J2c] = "J2";
  130. }
  131.  
  132. continue;
  133. }
  134.  
  135. if (isThereJ1) {
  136. for (set <string>::iterator it = Pack.begin(); it != Pack.end(); it++) {
  137. A[J1r][J1c] = *it;
  138. if (check3(r1, c1) &&
  139. check3(r2, c2)) {
  140. cout << "Solution exists." << endl;
  141. cout << "Replace J1 with " << (*it) << "." << endl;
  142. cout << "Put the first square to (" << r1 << ", " << c1 << ")." << endl;
  143. cout << "Put the second square to (" << r2 << ", " << c2 << ").";
  144. return ;
  145. }
  146. A[J1r][J1c] = "J1";
  147. }
  148. continue;
  149. }
  150. if (isThereJ2) {
  151. for (set <string>::iterator it = Pack.begin(); it != Pack.end(); it++) {
  152. A[J2r][J2c] = *it;
  153. if (check3(r1, c1) &&
  154. check3(r2, c2)) {
  155. cout << "Solution exists." << endl;
  156. cout << "Replace J2 with " << (*it) << "." << endl;
  157. cout << "Put the first square to (" << r1 << ", " << c1 << ")." << endl;
  158. cout << "Put the second square to (" << r2 << ", " << c2 << ").";
  159. return ;
  160. }
  161. A[J2r][J2c] = "J2";
  162. }
  163. continue;
  164. }
  165. cout << "Solution exists." << endl;
  166. cout << "There are no jokers." << endl;
  167. cout << "Put the first square to (" << r1 << ", " << c1 << ")." << endl;
  168. cout << "Put the second square to (" << r2 << ", " << c2 << ").";
  169. return ;
  170. }
  171. }
  172. cout << "No solution.";
  173. }

E

dfs+剪枝

剪完由超时变成了31ms....

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. int a[];
  16. int n,k;
  17. map<string,int>mp;
  18. string str;
  19. int s1[],s2[];
  20. int flag;
  21. int book[];
  22. vector<int>ans[];
  23.  
  24. void dfs(int l,int r,int sum){
  25. if(r==k){
  26. flag=;
  27. return;
  28. }
  29. if(s2[r]==sum){
  30. dfs(,r+,);
  31. return;
  32. }
  33. int pre=-;
  34. for(int i=;i<n&&!flag&&s1[i]+sum<=s2[r];i++){
  35. if(book[i]==-&&s1[i]!=pre){///剪枝
  36. pre=s1[i];
  37. book[i]=r;
  38. dfs(l+,r,s1[i]+sum);
  39. if(!flag){
  40. book[i]=-;
  41. }
  42. }
  43. }
  44. }
  45.  
  46. int main(){
  47. #ifndef ONLINE_JUDGE
  48. // freopen("input.txt","r",stdin);
  49. #endif
  50. std::ios::sync_with_stdio(false);
  51. string element[] = {
  52. "kong","H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar",
  53. "K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br",
  54. "Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te",
  55. "I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm",
  56. "Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn",
  57. "Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm"
  58. };
  59. for(int i=;i<sizeof(element)/sizeof(element[]);i++){
  60. mp[element[i]]=i;
  61. }
  62. cin>>n>>k;
  63. for(int i=;i<n;i++){
  64. cin>>str;
  65. s1[i]=mp[str];
  66. }
  67. for(int i=;i<k;i++){
  68. cin>>str;
  69. s2[i]=mp[str];
  70. }
  71. sort(s1,s1+n);
  72. sort(s2,s2+k);
  73. memset(book,-,sizeof(book));
  74. dfs(,,);
  75. if(flag){
  76. cout<<"YES"<<endl;
  77. for(int i=;i<n;i++){
  78. ans[book[i]].pb(s1[i]);
  79. }
  80. for(int i=;i<k;i++){
  81. cout<<element[ans[i][]];
  82. for(int j=;j<ans[i].size();j++){
  83. cout<<"+"<<element[ans[i][j]];
  84. }
  85. cout<<"->"<<element[s2[i]]<<endl;
  86. }
  87. }
  88. else {
  89. cout<<"NO"<<endl;
  90. }
  91. }

Codeforces Beta Round #65 (Div. 2)的更多相关文章

  1. Codeforces Beta Round #65 (Div. 2) C. Round Table Knights

    http://codeforces.com/problemset/problem/71/C 题意: 在一个圆桌上有n个人,每个人要么是1,要么就是0,现在要判断是否能由一些1相连构成正多边形. 思路: ...

  2. codeforces水题100道 第二十一题 Codeforces Beta Round #65 (Div. 2) A. Way Too Long Words (strings)

    题目链接:http://www.codeforces.com/problemset/problem/71/A题意:将长字符串改成简写格式.C++代码: #include <string> ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. MVC控制器返回重定向操作

    注意:在使用Ajax请求后台时是不能在后台重定向的! 解决方案: if (userInfoService.CheckUser(username, psd, out msg)) { , msg = &q ...

  2. APPium-Xpath,swipe练习

    写自动化测试,实现 滚动到 口碑最佳 部分,并且打印出所有 口碑最佳 部分的5个应用名称 # coding:utf-8from appium import webdriverimport time d ...

  3. idea 与springboot 快捷键

    ctrl + m 还原 查询 getmapping 修改默认端口号

  4. java 中AIO,BIO,NIO的区别(茅塞顿开)

    看到知乎上一篇回答,解决了疑惑:https://www.zhihu.com/question/56673416 第三位作者的回答...原谅我没有登录知乎,不然一定给他留赞. 也可以参考:https:/ ...

  5. es6 初级之展开运算符

    1.1 先看一个求最大值的例子 <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  6. XML报错:The reference to entity "characterEncoding" must end with the ';' delimite

    解决方法: 在web.xml增加如下配置: <filter>  <filter-name>encodingFilter</filter-name>  <fil ...

  7. Homebrew安装与使用

    Homebrew是什么? 官方解释: Homebrew是以最简单,最灵活的方式来安装苹果公司在MacOS中不包含的UNIX工具. 官网:传送门 Git仓库地址:传送门 Homebrew 怎么安装 ?怎 ...

  8. 计算机网络协议包头赏析-TCP

    仍然先把TCP报文段的格式放在这里,然后我们看图说话: TCP报文段也分为首部和数据两部分,首部默认情况下一般是20字节长度,但在一些需求情况下,会使用“可选字段”,这时,首部长度会有所增加. 下面, ...

  9. requirejs源码分析

  10. week06 08 postman 测试jsonrpc

    用postman来测试rpc需要添加特别的字段 ’ { "jsonrpc":"2.0", "id":"123", &qu ...