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后和给 ...
随机推荐
- 认识HTML5
引言,认识两个标准制定的组织 在讲什么是Html5之前得先了解两个组织:WHATWG :网页超文本技术工作小组(英语:Web Hypertext Application Technology Work ...
- android 数据存储的四种方式.
Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File.由于Android系统中,数据基本都是私有的的,都是存放 ...
- php学习日志(3)-echo&print
在php中,结果输出一共有两种方式:echo和print,下面将对两种方式做一个比较. echo与print的区别: echo print 连续输出字符串 能连续输出多个字符串 只能输出一个字符串 ...
- PHP获取搜索引擎关键字来源(百度、谷歌、雅虎、搜狗、搜搜、必应、有道)
<?php //获取来自搜索引擎入站时的关键词 function get_keyword($url,$kw_start) { $start=stripos($url,$kw_start); $u ...
- Ducci Sequence
Description A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers ( ...
- 【转】 GDB 常用调试方法
一.多线程调试 多线程调试可能是问得最多的.其实,重要就是下面几个命令: info thread 查看当前进程的线程. thread <ID> 切换调试的线程为指定ID的线程. break ...
- php + mysql + sphinx 的全文检索(2)
简单 使用php api 去查询 sphinx 的索引数据 $sphinx = new SphinxClient(); $sphinx->SetServer ( ...
- TOPAPI 消息通知机制
接收用户订阅消息 public class UserSubMain { public static void main(String[] args ) throws ApiException { St ...
- (转)关于ARM9协处理器CP15及MCR和MRC指令
网址:http://blog.csdn.net/zhou1232006/article/details/6150198 在基于ARM的嵌入式应用系统中,存储系统通常是通过系统控制协处理器CP15完成的 ...
- 浅淡Windows7 32位与64位/x86与x64的区别
看到有很多会员问到底是选Windows7 x86,还是选x64.这里简单的谈一下这这两种系统的区别. 简单的说x86代表32位操作系统 x64代表64位操作系统. 简单的判断电脑是否支持64位操作系 ...