题目: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. spring-cloud-bus

    安装rabbitmq 依赖erlang: http://erlang.org/download/otp_win64_18.2.exe

  2. CSS实现不固定宽度和高度的自动居中

    有时候我们需要实现下面这种效果: 嘎嘎,撑大高度不让你剧中 嘎嘎,撑大高度不让你剧中 嘎嘎,撑大高度不让你剧中 嘎嘎,撑大高度不让你剧中 嘎嘎,撑大高度不让你剧中 嘎嘎,撑大高度不让你剧中 嘎嘎,撑大 ...

  3. Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll

    Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...

  4. Ubuntu安装google Gtest

    (1) 下载源码:http://code.google.com/p/googletest/gtest-1.7.0 (2013)gtest-1.7.0 (2010) (2) README编译指南126 ...

  5. 《WPF程序设计指南》读书笔记——第8章 依赖属性

    1.依赖属性的效果 一旦规定视觉树上一个对象的fontsize属性,那么属于他的节点之下的所有对象都会沿袭这个属性,然而如果某个子节点明确的设定了自己的fontsize,就不会沿袭父节点的fontsi ...

  6. jsp分页代码之pageUtil类

    pageUtil类负责得到每页的开始数和结束数 package control; public class PageUtil { private int pageSize;//每页显示的条数 priv ...

  7. hdu 4622 Reincarnation SAM模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有Q次区间查询(Q <= 10000),问区 ...

  8. IOS设备滑动事件

    只要手指触摸屏幕,滑动,从屏幕离开,系统都会产生UIEvent对象类型的事件---当然包括UITouch事件 – touchesBegan:withEvent:   当用户触摸到屏幕时调用方法 – t ...

  9. NGUI系列教程十(Scroll View实现触摸滚动相册效果)

    NGUI中提供了两种Scroll View 一种是通过手指或鼠标滑动视图时移动平面物体,另一种则是直接移动摄像机,他们各有各的好处.但是NGUI提供的Scroll View很难实现类似Android ...

  10. EXTJS 4.2 资料 控件之Window窗体自动填充页面

    1.html页面代码: <div id="component" style="width:100%;height:100%"> <body&g ...