直接看示例输入输出+提示

1. 统计所有数的和 sum,然后求 sum/(n/2) 的到一半数的平均值

  6

  1 5 7 4 4 3 -》1+5+7+4+4+3=24  分成3组 每组值为8

  int sumavg=sum/(n/2)=8

2. int z=sumavg-x[i]

if(x[j]==z&&!dp[i]&&!dp[j]) //如果当前数为该输出的数,且i,j没有输出过,则输出 i,j (数组下标), 且dp[i]=dp[j]=1;  

AC代码可以解释解题答案

 #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,x[],dp[];
while(scanf("%d",&n)!=EOF)
{
int sumavg=;
for(i=; i<=n; i++)
{
scanf("%d",&x[i]);
sumavg+=x[i];
}
sumavg=sumavg/(n/);
memset(dp,,sizeof(dp));
for(int i=; i<n; i++)
{
int z=sumavg-x[i];
for(int j=i+; j<=n; j++)
{
if(x[j]==z&&!dp[i]&&!dp[j])
{
dp[i]=;
dp[j]=;
printf("%d %d\n",i,j);
break;
}
}
}
}
return ;
}

CodeForces 701A Cards的更多相关文章

  1. Codeforces 701A. Cards(水)

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  2. codeforces 701A A. Cards(水题)

    题目链接: A. Cards 题意: 问两个数的和相同,怎么组合; AC代码: #include <iostream> #include <cstdio> #include & ...

  3. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  4. Codeforces 999F Cards and Joy(二维DP)

    题目链接:http://codeforces.com/problemset/problem/999/F 题目大意:有n个人,n*k张卡牌,每个人会发到k张卡牌,每个人都有一种喜欢的卡牌f[i],当一个 ...

  5. Codeforces 830B - Cards Sorting 树状数组

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. codeforces #364a Cards

    cf的a题没什么好说到,100的量级,每个人给2张牌,使每个人手中的牌点数相等.保证有一种分配方案. 对每个人,先计算出手中的牌的点数,然后循环两遍拿牌就可以.   A. Cards time lim ...

  7. CodeForces 626B Cards

    瞎搞题...凭直觉+猜测写了一发,居然AC了.. #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  8. Codeforces 1278F: Cards

    题目传送门:CF1278F. 题意简述: 有 \(n\) 个独立随机变量 \(x_i\),每个随机变量都有 \(p = 1/m\) 的概率取 \(1\),有 \((1-p)\) 的概率取 \(0\). ...

  9. CodeForces 830B - Cards Sorting

    将每个数字的位置存进该数字的vector中 原数组排个序从小到大处理,每次在vector里二分找到距离当前位置“最远”的位置(相差最大),更新答案 树状数组维护每个数字现在的位置和原位置之差 #inc ...

随机推荐

  1. MySQL基础 - 注意事项

    AND比OR优先级高,故在同时使用AND和OR进行查找时记得加上小括号,当同时存在多个条件时统一加上括号是个好习惯. NULL不参与搜索,即使使用LIKE '%'也匹配不到值为NULL的记录. LIK ...

  2. perl 简单学习,安装perl模块

    检查是否安装了某个perl模块 有多种方式 0.perldoc perlinstall 列出所有的模块及版本号 1. perl -M模块名 -e 1(模块名不加空格) 没有返回值则说明有此模块 2.p ...

  3. python logging 模块

    我有几个项目中使用了 sentry 捕获 ERROR 级别的日志,现在遇到一个问题:本地调试的时候,日志设置中,所有的 handler(包括 root) 都只打到 console 上面,但是本地调试中 ...

  4. mvc control 请求两次问题

    今天在做项目时,突然发现一个mvc 的control中action被执行了两次,最终发现是由于favicon.ico导致的.问题代码: <link rel="shortcut icon ...

  5. Bootstrap系列 -- 32. 按钮垂直分组

    实际运用当中,总会碰到垂直显示的效果.在Bootstrap框架中也提供了这样的风格.我们只需要把水平分组的“btn-group”类名换成“btn-group-vertical”即可. <div ...

  6. opc 方面研究

    http://opcuaservicesforwpf.codeplex.com/ WPF + OPC UA

  7. js的各种继承

    请先看这个链接:https://segmentfault.com/a/1190000002440502 还有一个里边有js的采用临时方法的继承 http://javapolo.iteye.com/bl ...

  8. 使用jquery获取url及url参数的方法及定义JQuery扩展方法

    1.jquery获取url很简单,代码如下: window.location.href; 其实只是用到了javascript的基础的window对象,并没有用jquery的知识. 2.jquery获取 ...

  9. [USACO2004][poj1985]Cow Marathon(2次bfs求树的直径)

    http://poj.org/problem?id=1985 题意:就是给你一颗树,求树的直径(即问哪两点之间的距离最长) 分析: 1.树形dp:只要考虑根节点和子节点的关系就可以了 2.两次bfs: ...

  10. Android之POST方法的使用

    java代码 package xidian.dy.com.chujia; import android.os.Bundle; import android.os.Handler; import and ...