题目:http://codeforces.com/contest/382

Ksenia and Pan Scales

一个求天平是否能够平衡的题目。。。水题,注意一下结果的输出就行。

 #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 ;
}

Arithmetic Progression

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

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. firefox 自定义快捷键

    firefox 更新到44或45,发现原来的更改快捷键的扩展没了!!!

  2. 多线程的单元测试工具 - GroboUtils

    写过Junit单元测试的同学应该会有感觉,Junit本身是不支持普通的多线程测试的,这是因为Junit的底层实现上,是用System.exit退出用例执行的.JVM都终止了,在测试线程启动的其他线程自 ...

  3. Android基于GridView实现的翻牌游戏效果

    好久没有写博客了,上一篇博文距现在都有三个多月了,实在是惭愧.但是这段时间仍然是在忙于项目或是自我充电.这几天实现了一个基于GridView的翻牌动画效果,这里就将其整理出来同各位分享. 一.整体介绍 ...

  4. spark 1.3.0下的问题

    1.在spark SQL的一个test中 无论是registerAsTable还是registerTempTable 都会有问题,经过查找各种资料,采用如下的方式: val sqlCon=new or ...

  5. C# window service的创建

    其实我也是第一次在博客园写博客,看到那些高手说自己要多动手写博客,于是乎自己也尝试尝试. 废话不多说.这几天在研究window service,通过查找各种大神写的博客,我终于成功的自己写出来了. 下 ...

  6. jQuery 的 json 格式的处理问题

    在实际的使用中时常会发生一些ajax验证的诡异事件,如我在一个文件中使用json传送数据,结果出现了当数据发送到服务器端时(后端主要呈现的是对json数据对象的数据库查询操作),结果显示的是数据已经插 ...

  7. Oracle全表扫描

    优化器在形成执行计划时需要做的一个重要选择——如何从数据库查询出需要的数据.对于SQL语句存取的任何表中的任何行,可能存在许多存取路径(存取方法),通过它们可以定位和查询出需要的数据.优化器选择其中自 ...

  8. DataGrid中取HyperLinkColumn列的值,处理DataGrid中绑定的特殊字符

    DataGrid中取HyperLinkColumn列的值. /// <summary> /// 对datagrid中标签进行编码,处理特殊字符 /// </summary> / ...

  9. sql之独立子查询和相关子查询总结

    1.独立子查询:顾名思义:就是子查询和外层查询不存在任何联系,是独立于外层查询的: 下面就看一个例子: 有一张订单表 Sales.Order 和一张 客户表 Sales.Customer 下面的sql ...

  10. linux驱动系列之makefile

    在linux环境下做嵌入式无论是编写应用程序还是驱动程序等等,都需要用make来进行程序的编译,就需要学会自己编写Makefile.Makefile主要的作用有3点:1.决定编译哪些文件 2.怎样编译 ...