Codeforces Round #224 (Div. 2)
题目:http://codeforces.com/contest/382
一个求天平是否能够平衡的题目。。。水题,注意一下结果的输出就行。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std; int main()
{
int i,len;
int L,R,x,sum;
char a[],b[];
while(~scanf("%s",a))
{
L=; R=;
for(i=; i<strlen(a); i++)
{
if(a[i]=='|')
break;
L++;
}
R=strlen(a)--L;
scanf("%s",b);
len=strlen(b);
x=abs(L-R); if(x>len)
printf("Impossible\n");
else if((len-x)%==)
printf("Impossible\n");
else
{
sum=L+R+len;
for(i=; i<L; i++)
printf("%c",a[i]);
for(i=; i<sum/-L; i++)
printf("%c",b[i]); printf("%c",a[L]);
for(i=sum/-L; i<len; i++)
printf("%c",b[i]);
for(i=L+; i<strlen(a); i++)
printf("%c",a[i]);
printf("\n");
}
}
return ;
}
已知n个数,再给一个数,求有多少种数,能使序列构成等差数列。。
比赛的时候思路有的混乱,没做,今天做了一下,1Y
网上还有按照 间隔分的做法,思路差不多。。代码也挺长的。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <algorithm>
using namespace std; int a[],b[];
int n;
int check(int d[],int ant)//判断是否符合等差数列的条件
{
int i,x;
for(i=; i<n; i++)
b[i]=d[i]; b[n]=ant;
sort(b,b+n+);
x=b[]-b[];
for(i=; i<=n; i++)
{
if((b[i]-b[i-])!=x)
return ;
}
return ;
} int main()
{
int i,f,x,sum,ans;
while(~scanf("%d",&n))
{
map<int,int>mp;
map<int,int>::iterator iter;
x=;
for(i=; i<n; i++)
scanf("%d",&a[i]); if(n==) //特判
printf("-1\n");
else
{
sort(a,a+n);
f=;
for(i=; i<n; i++)
if(a[i-]==a[i])
{
f=; break;
} if(a[]==a[n-])//特判
printf("1\n%d\n",a[]);
else if(f)
printf("0\n");//特判
else
{
x=a[]-a[];
if(check(a,a[]-x)) //情况1,假设前两个与整个序列相符合,而且整个序列已经等差,前面
{
mp[a[]-x]++;
}
if(check(a,a[n-]+x)&&mp[a[n-]+x]==)//情况1,假设前两个与整个序列相符合,而且整个序列已经等差,后面
mp[a[n-]+x]++;
for(i=; i<n; i++) //情况2,假设前两个与整个序列相符合,而且整个序列没有等差
{
if((a[i]-a[i-])!=x)
{
if(check(a,a[i-]+x)&&mp[a[i-]+x]==)
mp[a[i-]+x]++;
break;
}
}
if(n>=) //情况3,假设前两个与整个序列相符合
{
x=a[]-a[];
if(check(a,a[]+x)&&mp[a[]+x]==)
mp[a[]+x]++;
}
else //情况4,只有两个,取中间的值
{
if((a[]+a[])%==)
{
if(check(a,(a[]+a[])/)&&mp[(a[]+a[])/]==)
mp[(a[]+a[])/]++;
}
}
sum=;
iter=mp.begin();
while(iter!=mp.end())
{
sum++;
iter++;
}
if(sum==)
printf("%d\n",sum);
else
{
printf("%d\n",sum);
ans=;
iter=mp.begin();
while(iter!=mp.end())
{
ans++;
if(ans!=sum)
printf("%d ",iter->first);
else
printf("%d\n",iter->first);
iter++;
}
}
}
}
}
return ;
}
Codeforces Round #224 (Div. 2)的更多相关文章
- Codeforces Round #224 (Div. 2) A. Ksenia and Pan Scales
A. Ksenia and Pan Scales time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- android studio引入第三方包记录
1.添加jar文件 将jar文件复制至app module目录下的libs文件夹下,然后打开app module目录下的build.gradle配置文件,在dependencies项中添加配置命令,这 ...
- corsproxy
安装完 node.js运行 npm install -g corsproxy安装完成 corsproxy
- WPF xmal绑定数据,当显示数据过长用省略号代替的方法
有时候会遇到这种情况,用了数据绑定显示的数据太长时,如何让过长的数据显示规定的长度,多余的用省略号代替呢,自己写了个简单的小例子和大家分享一下^_^,我也是学习WPF不久,这是我第一次写博客,有问题还 ...
- 模式对话框里的CheckedChanged事件
问题: 模式对话框里的CheckedChanged事件不被触发: 解决方法: 一.先不直接showModalDialog出要的页面,而是要放一个中单页面 window.showModalDialo ...
- 怎么在SQL Server 2008中还原.mdf数据文件
还原数据库文件的过程中,只有mdf文件,该怎么还原?在原来的SQL Server 2005中直接点击数据库然后附加就可以还原,但是在2008 版本中附加数据库文件则会出错(只有mdf文件){执行Tra ...
- ios 保存本地数据的方法
1. NSString *path = [[NSBundle mainBundle] pathForResource:@"文件名" ofType:@"plist" ...
- poj 2226 Muddy Fields (转化成二分图的最小覆盖)
http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- Delphi XE5 android openurl(转)
直接上代码: unit OpenViewUrl; interface // URLEncode is performed on the URL// so you need to format it p ...
- 明晰三种常见存储技术:DAS、SAN和NAS
随着企业网络应用的时间和应用的数据量的加大,企业已经感觉到存储容量和性能落后与网络的应用发展需求,特别是流媒体企业,在这种应用条件下满足用户的存储需求的技术应用诞生,DAS.NAS和SAN三种存储技术 ...
- CSS 命名规范及标题供参考与学习
一.CSS 命名规范 XHTML-CSS写作建议 所有的xhtml代码小写 属性的值一定要用双引号("")括起来,且一定要有值 每个标签都要有开始和结束,且要有正确的层次 空元 ...