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> ...
随机推荐
- node.js定时任务 node-schedule
先安装 node-schedule npm install node-schedule //1:确定时间 //例如:2014年2月14日,15:40执行 var schedule = require( ...
- Firefox What's New 太难找了
Firefox每次更新版本,不知道更新了什么,找不到Waht‘s New,做个记录! 1.点击mozilla下拉 2.最左侧 MOZILLA>SUPPORT>Firefox 3.https ...
- Proftpd 服务器安装配置
yum install proftpd 如果提示没有找到源 rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6 ...
- 爬虫--requests模块高级(代理和cookie操作)
代理和cookie操作 一.基于requests模块的cookie操作 引言:有些时候,我们在使用爬虫程序去爬取一些用户相关信息的数据(爬取张三“人人网”个人主页数据)时,如果使用之前requests ...
- linux与linux远程桌面
https://blog.csdn.net/m0_37343696/article/details/79252979
- How to Pronounce T + Dark L
How to Pronounce T + Dark L Share Tweet Share Tagged With: Dark L The T and Dark L combination is co ...
- avalon2学习教程 03数据填充
数据填充是一个模版最基础的功能,直接从JSON(vm)取出数据,放到适当的位置上.在静态模板中,不区分文本与HTML,只看你的字符串是否有< >来决定生成文本节点与元素节点.但MVVM中, ...
- bcrelay广播包转发器
https://www.mankier.com/8/bcrelay PPTP原是基于PPP的三层通信协议,加入bcrelay后可以将二层的广播包转发到PPTP的client端 在openwrt中实现的 ...
- .NET(C#) win Form窗体的常用属性以及事件
使用.Net编写Windows程序,对于窗体控制常见项目 属性:1.让窗体在启动时在指定位置出现 form1.StartPosition Manual CenterScreen WindowsDefa ...
- [C语言]数据类型与计算
------------------------------------------------------------------------------------------------- 实际 ...