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> ...
随机推荐
-
pdf在线处理网站
https://smallpdf.com/unlock-pdf
-
Ubuntu下安装JDK以及相关配置
1.查看系统位数,输入以下命令即可 getconf LONG_BIT 2.下载对应的JDK文件,我这里下载的是jdk-8u60-linux-64.tar.gz 3.创建目录作为JDK的安装目录,这里选 ...
-
AOJ 0525 穷举
题意:有一个烤饼器可以烤r行c列的煎饼,煎饼可以正面朝上(用1表示)也可以背面朝上(用0表示).一次可将同一行或同一列的煎饼全部翻转.现在需要把尽可能多的煎饼翻成正面朝上,问最多能使多少煎饼正面朝上? ...
-
移动端远程关闭PC端实现(一)需求设计
公司有台半新不旧的电脑,因无甚大用,就拿来做了服务器,服务于民.服务器所提供的功能不是太多,无非是数据库以及svn服务. 公司每天下班会断电,我们吧会常常忘记关闭服务器,所以服务器非正常关机的次数约等 ...
-
android 添加左右滑屏手势
今天要在自己的项目中添加左右滑动,实现日期的加减(原来已经做了加减按键).滑动在一个中间的layout中进行 思路:添加左右划屏幕判断,得到判断后模拟加减按键按下. 模拟按键按下用 mbotton.p ...
-
替换 window.location当中的某个参数的值(而其它值不变)JS代码
在后台与前台的交互操作中,需要替换location当中的某个参数的值(而其它值不变)时,会用到以下函数: 说明: win:传入的窗口句柄,如,window或window.parent等forceAdd ...
-
ubuntu安装 cober 笔记
设置原始Ubuntu原始Root密码 安装Mysql 安装Jdk 拷贝Cober到Linux,启动服务(看日志) 设置原始Ubuntu原始Root密码 $ sudo passwd root 修改系统文 ...
-
js 获取二级域名
js获取页面完整地址: window.location.href; var s =" https://ejym.baidu.com"; var h = s.s ...
-
MTK平台-抓取蓝牙log
一.MTKLOG抓取 .在拔号键盘输入暗码 *#*##*#* 进入工模EngineerMode .在 Log and Debugging -> MTKLogger 点击开始 .MTKLog存储路 ...
-
每月学习数理统计--《统计学习方法—李航》(3): SVM
1. SVM的最优化问题 2.拉格朗日乘数法,对偶条件KKT条件 3.软件隔支持向量机 4.非线性支持向量机,核函数 5.SMO算法 1. SVM的最优化问题 支持向量机(Support Vector ...