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后和给 ...
随机推荐
- Facebook SDK
<?php session_start(); header('Content-type:text/html; charset=UTF-8'); require_once './facebook- ...
- tomcat源码解读(2)–容器责任链模式的实现
责任链模式:责任链模式可以用在这样的场景,当一个request过来的时候,需要对这个request做一系列的加工,使用责任链模式可以使每个加工组件化,减少耦合.也可以使用在当一个request过来的时 ...
- zencart后台增加菜单选项
如果要在程序中使用额外的参数,在后台控制,添加到菜单属性 在后台 SQL脚本 运行如下 SQL语句 INSERT INTO configuration (configuration_title, co ...
- Python生成验证码
#!/usr/bin/env python #coding:utf8 import random #方法1: str_code='zxcvbnmasdfghjklqwertyuiopZXCVBNMAS ...
- python 实现文件批量拷贝
场景:某个文件夹下面包含数量巨大的文件,需求需要将这些文件按组(比如5000个一组)存放到不同的目录中去. # Filename: CopyFiles.py import os import os.p ...
- 【socket】Socket的三个功能类TCPClient、TCPListener 和 UDPClient
Socket的三个功能类TCPClient.TCPListener 和 UDPClient (转) 应用程序可以通过 TCPClient.TCPListener 和 UDPClient 类使用传输控制 ...
- parsing html in asp.net
http://stackoverflow.com/questions/5307374/parsing-html-page-in-asp-net http://htmlagilitypack.codep ...
- 手写快速排序(QuickSort)
#include<iostream> #include<stdio.h> #include<algorithm> using namespace std; int ...
- 实时数据处理环境搭建flume+kafka+storm:4.storm安装配置
1.解压 apache-storm-0.9.3.tar.gz 2.修改配置文件 conf/storm.yaml --zk地址 storm.zookeeper.servers: - " ...
- QR code 金庸小说体(二)
传说 在二维码世纪,流传着这样一个传说,long long ago,武林一片混乱,这时魔教二长老创立了一门绝世武功——QR code,随后称霸武林.但同时也遭到武林中人的觊觎和反抗,各大武林正派掌门人 ...