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)的更多相关文章

  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. python day10 数据库(mysql基础)

    一.数据库的概念 数据:事物的特征 数据库的本质是:通过套接字进行通信,来读存数据的一种软件,由于每次开发人员写程序都得写数据的套接字,所以诞生了数据库这个软件,减少重复劳动.(sql语句通用) 数据 ...

  2. db连接驱动

    1.oracle 驱动jar包-->ojdbc6.jar 驱动类-->oracle.jdbc.driver.OracleDriver 驱动连接--> 第一种:jdbc:oracle: ...

  3. java配置slf4j日志系统

    首先要导入的包: import: 每个类中加入下面,其中 RdiFtpDownload.class 是当前的类名.class 然后就可以打日志了: 配置 log4j.properties log4j. ...

  4. 笔记本移动位置,切换网络ip后,虚拟机的mac系统无法联网解决

    1.手动配置新的ip

  5. C++复习:多态

    多态 问题引出(赋值兼容性原则遇上函数重写)     面向对象新需求     C++提供的多态解决方案     多态案例     多态工程意义         面向对象三大概念.三种境界(封装.继承. ...

  6. 使用DDOS deflate抵御少量DDOS攻击

    DDoS-Deflate是一款非常小巧的防御和减轻DDoS攻击的工具,它可以通过监测netstat来跟踪来创建大量互联网连接的IP地址信息,通过APF或IPTABLES禁止或阻档这些非常IP地址. 工 ...

  7. Redis进阶实践之二如何在Linux系统上安装安装Redis(转载)(2)

    Redis进阶实践之二如何在Linux系统上安装安装Redis 一.引言 上一篇文章写了“如何安装VMware Pro虚拟机”和在虚拟机上安装Linux操作系统.那是第一步,有了Linux操作系统,我 ...

  8. 转: 日期格式参考extjs api文档中的Date类型

    var md = new Ext.form.DateField({ //下面的格式是:2000-01-01 00:00:00 format: 'Y-m-d H:i:s', ............ } ...

  9. LeetCode OJ 79. Word Search

    题目 Given a 2D board and a word, find if the word exists in the grid. The word can be constructed fro ...

  10. jquery实现分页+单删批删

    //定义一个分页的方法 public function fenye(){ //查询满足条件的总条数 $count = M("regis")->count(); //设置每页显 ...