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> ...
随机推荐
- Spring.net介绍及MVC中应用
Spring.net两大核心内容: IOC(控制反转) 传统的面相对象思维模式是对象A依赖对象B,对象B的实例化和调用都在对象A中发生,一旦对象B中发生变化,对象A也要随之变化,这样使得程序间行程了紧 ...
- git fail to push some refs....
出现错误的主要原因是github中的README.md文件不在本地代码目录中 可以通过如下命令进行代码合并[注:pull=fetch+merge] git pull --rebase origin m ...
- linux RPM包管理
查询系统是否安装某个应用 rpm -qa | grep xx 查询系统某个应用的版本信息 rpm -qi 软件包信息 查询某个软件的安装位置 rpm -ql 软件包名 查询文件属于哪个软件 ...
- vue 的父组件和子组件互相获取数据和方法
父组件主动获取子组件的数据和方法 一.ref(但不能实时更新获取) 1.调用子组件的时候 定义一个ref <child ref="headerChild"></c ...
- JavaScript随机生成信用卡卡号的方法
这段JS代码根据信用卡卡号产生规则随机生成信用卡卡号,是可以通过验证的,仅供学习参考,请不要用于非法用途,否则后果自负. var visaPrefixList = new Array( "4 ...
- python实现最大重叠子串的查找
#!/usr/bin/python #查找最大重叠子串 def FindMaxDup(in_str): str_len = len(in_str) result = '' #逐级扩大搜索长度# lev ...
- U3D GPU蒙皮
在U3D中默认情况下是使用CPU蒙皮的,在BUILDING SETTING中的others中可以设置为GPU skinning
- js 替换字符串中所有匹配的字符
var str = 'abcadeacf'; var str1 = str.replace('a', 'o'); alert(str1); // 打印结果: obcadeacf var str2 = ...
- 那些年,我们追过的PHP自加自减运算(1)
------------------------------------------------------------------------------------------- PHP的运算符号 ...
- ubuntu 下安装和启动SSH 服务
安装OPENSSH 服务端 sudo apt-get install openssh-server 查看进程是否启动 ps -e | grep ssh 删除密钥文件 rm /etc/ssh/ssh_h ...