Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!
A. Santa Claus and a Place in a Class
模拟题。(0:12)
题意:n列桌子,每列m张桌子,每张桌子一分为2,具体格式看题面描述。给出n,m及k。求编号为k的桌子在第几行第几列是左还是右。
思路:由图知k为奇数在左边。每列有2*m个数,k/(2*m)然后就可以知道在第几列。然后数据小遍历找到第几行。
int main()
{
int n,m,k;
while(~scanf("%d%d%d",&n,&m,&k))
{
char c;
if(k%2) c='L';
else c='R';
int x=0,y=0;
y=k/(2*m);
if(k%(2*m)) y++;
k-=(y-1)*2*m;
while(k>0)
{
k-=2;
x++;
}
printf("%d %d %c\n",y,x,c);
}
return 0;
}
B. Santa Claus and Keyboard Check
贪心模拟题。(0:39)
题意:真没读懂,大概知道了样例怎么来的。给出两个串,每个字符可以唯一对应(变成)另外一个字符,问如果第一个字符串可以变为另外一个串,输出对应要变的字符。
思路:就是一顿乱判,用map存对应关系,可能是样例比较水吧,侥幸过了终判。
struct node
{
char x,y;
}a1[N];
int main()
{
string a,b;
cin>>a>>b;
if(a==b)
{
printf("0\n");
}
else
{
int f=0,len=0;
int len1=a.size();
int len2=b.size();
if(len1!=len2) f=1;
map<char,char>q;
int v[50];
memset(v,0,sizeof(v));
memset(a1,'0',sizeof(a1));
for(int i=0;i<len1&&i<len2;i++)
{
if(a[i]==b[i])
{
if(v[a[i]-'a']||v[b[i]-'a']) //已经有主了;
{
if(v[a[i]-'a']&&q[a[i]]!=b[i]) f=1;
if(v[b[i]-'a']&&q[b[i]]!=a[i]) f=1;
}
else q[a[i]]=b[i];
}
else
{
if(v[a[i]-'a']||v[b[i]-'a'])
{
if(v[a[i]-'a']&&q[a[i]]!=b[i]) f=1;
else if(v[b[i]-'a']&&q[b[i]]!=a[i]) f=1;
}
else
{
q[a[i]]=b[i];
q[b[i]]=a[i];
a1[len].x=a[i];
a1[len++].y=b[i];
}
}
v[a[i]-'a']=1;
v[b[i]-'a']=1;
}
if(f) printf("-1\n");
else
{
printf("%d\n",len);
for(int i=0;i<len;i++)
printf("%c %c\n",a1[i].x,a1[i].y);
}
}
return 0;
}
侥幸过了终判,中间WA了一发。(1:41)
题意:有一个串,只包含‘U’、‘L’、'R'、‘D’四种字符,分别表示往哪个方向走。小明要走一个序列,起点为p0,每次从pi走到pi+1(1<=i<n)。小明只会沿着格子走最短路。但路线可能有很多种。求n的最小值。
思路:由最后一个图发现每次经过一个点都走了相反的路线。一去一回这这便经过了一个点。所以求有多少相反对即可。(U和D、L和R分别为一个相反对)
int main()
{
int n;
int v[50];
memset(v,0,sizeof(v));
string a;
cin>>n>>a;
int ans=0;
char c=a[0];//当前状态,表示走的方向
for(int i=0;i<n;i++)
{
if((c=='L'&&a[i]=='R')||(c=='R'&&a[i]=='L')||(c=='U'&&a[i]=='D')||(c=='D'&&a[i]=='U'))//遇到相反对
{
c=a[i];//更新当前状态
ans++;
memset(v,0,sizeof(v));
v[a[i]-'A']=1;
continue;
}
if(c=='L'||c=='R')
{
if((a[i]=='U'&&v['D'-'A'])||(a[i]=='D'&&v['U'-'A']))
{
c=a[i];
ans++;
memset(v,0,sizeof(v));
}
v[a[i]-'A']=1;
}
else
{
if((a[i]=='L'&&v['R'-'A'])||(a[i]=='R'&&v['L'-'A']))
{
c=a[i];
ans++;
memset(v,0,sizeof(v));
}
v[a[i]-'A']=1;
}
}
ans++;//终点
printf("%d\n",ans);
return 0;
}
C题刚想到这个思路的时候学姐给了一个想法:每两个点之间只有两种方向。。。但按着这种思路WA在第六组了。。。
Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!的更多相关文章
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B
Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A
Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)
http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...
- codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法
A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心
E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟
D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- P1179 数字统计
题目描述 请统计某个给定范围[L, R]的所有整数中,数字 2 出现的次数. 比如给定范围[2, 22],数字 2 在数 2 中出现了 1 次,在数 12 中出现 1 次,在数 20 中出 现 1 次 ...
- 浅析cookie
基本概念:cookie是指web浏览器存储的少量数据,该数据会在每次请求一个相关的URL时自动传到服务器中. 以博客园为例,我们看看cookie有哪些属性: 1.Name:cookie的名称: 2. ...
- this关键字实现串联构造函数调用
在一个类中如果需要实现多个自定义构造函数,通常做法是在构造函数中实现各自的业务逻辑,如果这些业务逻辑的实现并非截然不同的话,显然不符合oop编程思想,极不利于维护,当然,我们也可以通过将相同的逻辑部分 ...
- Dynamic Median
题意: 设计一个数据结构,初始为空,支持以下操作: (1)增加一个元素,要求在log(n)时间内完成,其中n是该数据结构中当前元素的个数.注意:数据结构中允许有重复的元素. (2)返回当前元素集合的中 ...
- Android开发实现高德地图定位
1.获取Key 参考官方文档:http://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key 对于签名文件的获取建议 ...
- python中的seteuid
seteuid(...) seteuid(uid) Set the current process's effective user id.
- Spring中@Value的使用
- 46 Simple Python Exercises-Higher order functions and list comprehensions
26. Using the higher order function reduce(), write a function max_in_list() that takes a list of nu ...
- how to use Hexo
Hexo is a good tool to build a personal blog.Here are some good reference:1: https://hexo.io/zh-cn/d ...
- linux下C的建立、编译和运行 gcc (附上Windows下visual c++的用法)
2019/6/24 1. 环境:window10下安装了MobaXterm,这里申请了阿里云的服务账号,可以直接使用linux系统,避免安装虚拟机等. 2. 判断linux下是否有GCC编译工具(我们 ...