lightoj 1148 Mad Counting

链接http://lightoj.com/volume_showproblem.php?problem=1148

题意:民意调查,每一名公民都有盟友,问最少人数。

思路:考察的知识点有两个:第一是整数相乘取上整;第二是容器大小(ps:不能算一个知识点,只能算一个坑点)。

做题思路:排序,如果被调查的人有相同盟友人数(n)的个数(cnt)大于这个数+1,即:(cnt > n+1), 容器已满,只能新开辟一个容器来装盟友。

代码

 #include <iostream>
#include <cstdio>
#include <algorithm>
#define N 51
using namespace std; int a[N]; int main()
{
int t, ic = , n, i;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(i = ; i < n; i++)
scanf("%d", a+i);
sort(a, a+n);
int k , ans = , cnt = ;
for(i = ; i < n; i++)
{
if(i == || a[i] == a[i-]) cnt++;
else
{
k = (cnt+a[i-]) / (a[i-]+); //+1 是因为加上自己人数,分子加上a[i-1]是因为取上整
ans += k*(a[i-]+);
cnt = ;
}
}
ans += (cnt+a[n-]) / (a[n-]+) * (a[n-]+); //最后一组没有参加for循环的计算,这里单独算
printf("Case %d: %d\n", ic++, ans);
}
return ;
}

lightoj 1148 Mad Counting(数学水题)的更多相关文章

  1. LightOJ - 1148 - Mad Counting

    先上题目: 1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 3 ...

  2. 1148 - Mad Counting(数学)

    1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...

  3. light oj 1148 - Mad Counting

    1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...

  4. 天哪!毫无思绪!令人感到恐惧的数学(水题?)(TOWQs)

    这道题的题目描述灰常简单,第一眼看以为是一道十分水的题目: 但是!!!(我仔细一看也没有发现这背后隐藏着可怕的真相~) 下面给出题目描述: 给出一个整数x,你可以对x进行两种操作.1.将x变成4x+3 ...

  5. hdu 2710 Max Factor 数学(水题)

    本来是不打算贴这道水题的,自己却WA了三次.. 要考虑1的情况,1的质因子为1 思路:先打表 ,然后根据最大质因子更新结果 代码: #include<iostream> #include& ...

  6. ZOJ 1494 Climbing Worm 数学水题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=494 题目大意: 一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要 ...

  7. LightOJ 1338 && 1387 - Setu && LightOJ 1433 && CodeForces 246B(水题)

    B - B Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  8. HDU 1840 Equations (简单数学 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 ——每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2 ...

  9. zzulioj--1790-- 弹珠游戏(数学水题!)

    弹珠游戏 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 14  Solved: 10 SubmitStatusWeb Board Descriptio ...

随机推荐

  1. Codeforces Round #553 (Div. 2) C

    C. Problem for Nazar time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. java 数据存储

    简单的记录一下而已. 1.寄存器: 特点:快,存储有限. 存储地点:处理器内部. 2.堆栈 特点:仅次于寄存器快,通过堆栈指针在处理器获取支持.堆栈指针下移,分配内存,上移,释放内存.此外须知生命周期 ...

  3. 《英文版c++语言程序设计》

    compatibility [kəm,pætɪ'bɪlɪtɪ] n.兼容 compatible [kəm'pætɪb(ə)l] adj. 兼容的:能共处的:可并立的 interdependent [ɪ ...

  4. LeetCode 454. 4Sum II (C++)

    题目: Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are su ...

  5. 机器学习实战第二章----KNN

    tile的使用方法 tile(A,n)的功能是把A数组重复n次(可以在列方向,也可以在行方向) argsort()函数 argsort()函数返回的是数组中值从大到小的索引值 dict.get()函数 ...

  6. Web.config配置configSections学习

    文章:c# 配置文件之configSections配置 configSections节点需要位于configuration第一的位置,紧挨configuration. <configuratio ...

  7. mac下mysql5.7.10密码问题

    mysql5.7.10刚安装好,会生成一个随机密码. 如果没记住这个随机密码,那么到mysql/bin/下执行mysql_secure_installation命令 按照提示重置密码和其他选项. ps ...

  8. Java web 强制301跳转

    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader("Location" ...

  9. PHP开发工具(CodeLobster PHP Edition)

    参考:http://www.uzzf.com/soft/45948.html 产品名:ttrar.com 密    钥:dstp-187c-9cdd-9a60-e185-b280 CodeLobste ...

  10. Spring 中常用注解原理剖析

    前言 Spring 框架核心组件之一是 IOC,IOC 则管理 Bean 的创建和 Bean 之间的依赖注入,对于 Bean 的创建可以通过在 XML 里面使用 <bean/> 标签来配置 ...