Codeforces Beta Round #65 (Div. 2)
Codeforces Beta Round #65 (Div. 2)
http://codeforces.com/contest/71
A
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n;
- string str;
- cin>>n;
- rep(i,,n){
- cin>>str;
- if(str.length()<=){
- cout<<str<<endl;
- }
- else{
- cout<<str[];
- cout<<str.length()-;
- cout<<str[str.length()-]<<endl;
- }
- }
- }
B
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n,k,t;
- cin>>n>>k>>t;
- int sum=t*n*k/;
- int tmp=sum/k;
- for(int i=;i<tmp;i++) cout<<k<<" ";
- if(tmp<n){
- int p=sum-tmp*k;
- cout<<p;
- for(int i=;i<n-tmp-;i++) cout<<" "<<;
- }
- }
C
模拟
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- int a[];
- int n;
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- cin>>n;
- for(int i=;i<n;i++)cin>>a[i];
- int flag=;
- for(int i=;i<=n/;i++)
- if(n%i==)
- {
- for(int j=;j<i;j++)
- {
- flag=;
- for(int k=j;k<n;k+=i)
- flag&=a[k];
- if(flag)
- {
- cout<<"YES"<<endl;
- return ;
- }
- }
- }
- cout<<"NO"<<endl;
- }
D
大模拟
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- string A[][];
- bool check1(int r, int c) {
- set <char> S;
- int cnt = ;
- for (int i = r; i <= r+; i++)
- for (int j = c; j <= c+; j++)
- if (A[i][j] == "J1" ||
- A[i][j] == "J2") {
- cnt++;
- }
- else
- S.insert(A[i][j][]);
- return ( (S.size() + cnt) == );
- }
- bool check2(int r1, int c1, int r2, int c2) {
- for (int i = r1; i <= r1+; i++)
- for (int j = c1; j <= c1+; j++)
- if (r2 <= i && i <= r2+ &&
- c2 <= j && j <= c2+) {
- return false;
- }
- return true;
- }
- bool check3(int r, int c) {
- set <char> S;
- for (int i = r; i <= r+; i++)
- for (int j = c; j <= c+; j++)
- S.insert(A[i][j][]);
- return ( S.size() == );
- }
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n, m;
- cin >> n >> m;
- string tmpRank[] = {"", "", "", "", "", "", "", "", "T", "J", "Q", "K", "A"};
- string tmpSuit[] = {"C", "D", "H", "S"};
- set <string> Pack;
- for (int i = ; i < ; i++)
- for (int j = ; j < ; j++)
- Pack.insert(tmpRank[i] + tmpSuit[j]);
- bool isThereJ1 = false;
- int J1r;
- int J1c;
- bool isThereJ2 = false;
- int J2r;
- int J2c;
- for (int i = ; i <= n; i++)
- for (int j = ; j <= m; j++) {
- cin >> A[i][j];
- if (A[i][j] == "J1") {
- isThereJ1 = true;
- J1r = i;
- J1c = j;
- continue;
- }
- if (A[i][j] == "J2") {
- isThereJ2 = true;
- J2r = i;
- J2c = j;
- continue;
- }
- Pack.erase(Pack.find(A[i][j]));
- }
- vector <pair <int, int>> V;
- for (int r = ; r <= n-; r++)
- for (int c = ; c <= m-; c++)
- if (check1(r, c))
- V.push_back(make_pair(r, c));
- for (int i = ; i < V.size(); i++)
- for (int j = ; j < V.size(); j++) {
- if (i == j)
- continue;
- int r1 = V[i].first;
- int c1 = V[i].second;
- int r2 = V[j].first;
- int c2 = V[j].second;
- if (check2(r1, c1, r2, c2)) {
- if (isThereJ1 && isThereJ2) {
- for (set <string>::iterator it1 = Pack.begin(); it1 != Pack.end(); it1++)
- for (set <string>::iterator it2 = Pack.begin(); it2 != Pack.end(); it2++) {
- if (it1 == it2)
- continue;
- A[J1r][J1c] = *it1;
- A[J2r][J2c] = *it2;
- if (check3(r1, c1) &&
- check3(r2, c2)) {
- cout << "Solution exists." << endl;
- cout << "Replace J1 with " << (*it1) << " and J2 with " << (*it2) << "." << endl;
- cout << "Put the first square to (" << r1 << ", " << c1 << ")." << endl;
- cout << "Put the second square to (" << r2 << ", " << c2 << ").";
- return ;
- }
- A[J1r][J1c] = "J1";
- A[J2r][J2c] = "J2";
- }
- continue;
- }
- if (isThereJ1) {
- for (set <string>::iterator it = Pack.begin(); it != Pack.end(); it++) {
- A[J1r][J1c] = *it;
- if (check3(r1, c1) &&
- check3(r2, c2)) {
- cout << "Solution exists." << endl;
- cout << "Replace J1 with " << (*it) << "." << endl;
- cout << "Put the first square to (" << r1 << ", " << c1 << ")." << endl;
- cout << "Put the second square to (" << r2 << ", " << c2 << ").";
- return ;
- }
- A[J1r][J1c] = "J1";
- }
- continue;
- }
- if (isThereJ2) {
- for (set <string>::iterator it = Pack.begin(); it != Pack.end(); it++) {
- A[J2r][J2c] = *it;
- if (check3(r1, c1) &&
- check3(r2, c2)) {
- cout << "Solution exists." << endl;
- cout << "Replace J2 with " << (*it) << "." << endl;
- cout << "Put the first square to (" << r1 << ", " << c1 << ")." << endl;
- cout << "Put the second square to (" << r2 << ", " << c2 << ").";
- return ;
- }
- A[J2r][J2c] = "J2";
- }
- continue;
- }
- cout << "Solution exists." << endl;
- cout << "There are no jokers." << endl;
- cout << "Put the first square to (" << r1 << ", " << c1 << ")." << endl;
- cout << "Put the second square to (" << r2 << ", " << c2 << ").";
- return ;
- }
- }
- cout << "No solution.";
- }
E
dfs+剪枝
剪完由超时变成了31ms....
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- int a[];
- int n,k;
- map<string,int>mp;
- string str;
- int s1[],s2[];
- int flag;
- int book[];
- vector<int>ans[];
- void dfs(int l,int r,int sum){
- if(r==k){
- flag=;
- return;
- }
- if(s2[r]==sum){
- dfs(,r+,);
- return;
- }
- int pre=-;
- for(int i=;i<n&&!flag&&s1[i]+sum<=s2[r];i++){
- if(book[i]==-&&s1[i]!=pre){///剪枝
- pre=s1[i];
- book[i]=r;
- dfs(l+,r,s1[i]+sum);
- if(!flag){
- book[i]=-;
- }
- }
- }
- }
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- string element[] = {
- "kong","H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar",
- "K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br",
- "Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te",
- "I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm",
- "Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn",
- "Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm"
- };
- for(int i=;i<sizeof(element)/sizeof(element[]);i++){
- mp[element[i]]=i;
- }
- cin>>n>>k;
- for(int i=;i<n;i++){
- cin>>str;
- s1[i]=mp[str];
- }
- for(int i=;i<k;i++){
- cin>>str;
- s2[i]=mp[str];
- }
- sort(s1,s1+n);
- sort(s2,s2+k);
- memset(book,-,sizeof(book));
- dfs(,,);
- if(flag){
- cout<<"YES"<<endl;
- for(int i=;i<n;i++){
- ans[book[i]].pb(s1[i]);
- }
- for(int i=;i<k;i++){
- cout<<element[ans[i][]];
- for(int j=;j<ans[i].size();j++){
- cout<<"+"<<element[ans[i][j]];
- }
- cout<<"->"<<element[s2[i]]<<endl;
- }
- }
- else {
- cout<<"NO"<<endl;
- }
- }
Codeforces Beta Round #65 (Div. 2)的更多相关文章
- Codeforces Beta Round #65 (Div. 2) C. Round Table Knights
http://codeforces.com/problemset/problem/71/C 题意: 在一个圆桌上有n个人,每个人要么是1,要么就是0,现在要判断是否能由一些1相连构成正多边形. 思路: ...
- 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> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- MVC控制器返回重定向操作
注意:在使用Ajax请求后台时是不能在后台重定向的! 解决方案: if (userInfoService.CheckUser(username, psd, out msg)) { , msg = &q ...
- APPium-Xpath,swipe练习
写自动化测试,实现 滚动到 口碑最佳 部分,并且打印出所有 口碑最佳 部分的5个应用名称 # coding:utf-8from appium import webdriverimport time d ...
- idea 与springboot 快捷键
ctrl + m 还原 查询 getmapping 修改默认端口号
- java 中AIO,BIO,NIO的区别(茅塞顿开)
看到知乎上一篇回答,解决了疑惑:https://www.zhihu.com/question/56673416 第三位作者的回答...原谅我没有登录知乎,不然一定给他留赞. 也可以参考:https:/ ...
- es6 初级之展开运算符
1.1 先看一个求最大值的例子 <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- XML报错:The reference to entity "characterEncoding" must end with the ';' delimite
解决方法: 在web.xml增加如下配置: <filter> <filter-name>encodingFilter</filter-name> <fil ...
- Homebrew安装与使用
Homebrew是什么? 官方解释: Homebrew是以最简单,最灵活的方式来安装苹果公司在MacOS中不包含的UNIX工具. 官网:传送门 Git仓库地址:传送门 Homebrew 怎么安装 ?怎 ...
- 计算机网络协议包头赏析-TCP
仍然先把TCP报文段的格式放在这里,然后我们看图说话: TCP报文段也分为首部和数据两部分,首部默认情况下一般是20字节长度,但在一些需求情况下,会使用“可选字段”,这时,首部长度会有所增加. 下面, ...
- requirejs源码分析
- week06 08 postman 测试jsonrpc
用postman来测试rpc需要添加特别的字段 ’ { "jsonrpc":"2.0", "id":"123", &qu ...