可以暴力,但这里学习了一个新思路,就是把原式进行分解会得到[1/a[i]+1/a[j]],因为向下取整,我们可以发现,1作用于1结果为2,1作用于除了1之外的数结果为1,2作用于2结果为1,所以我们只需要进行对1,2,的查找就可以了,我们可以把结果进行化简得到一个最简式sum=a1*(a1+a2+other-1)+a2*(a2-1)/2

#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
long long m;
int a1=,a2=,other=;
for(int i=;i<n;i++)
{
cin>>m;
if(m==)
a1++;
else if(m==)
a2++;
else
other++;
}
int sum=a1*(a1+a2+other-)+a2*(a2-)/;
cout<<sum<<endl;
}
return ;
}

51nod1305的更多相关文章

  1. 51nod1305 Pairwise Sum and Divide

    题目链接:51nod 1305 Pairwise Sum and Divide 看完题我想都没想就直接暴力做了,AC后突然就反应过来了... Floor( (a+b)/(a*b) )=Floor( ( ...

  2. 51nod1305(简单逻辑)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1305 题意:中文题诶- 思路:1e5的数据直接暴力肯定是不行 ...

随机推荐

  1. Windows不要使用记事本编辑文本文件

    摘自:廖雪峰 千万不要使用Windows自带的记事本编辑任何文本文件.原因是Microsoft开发记事本的团队使用了一个非常弱智的行为来保存UTF-8编码的文件,他们自作聪明地在每个文件开头添加了0x ...

  2. 过滤器手动注入Service Bean方法

    @Override public void init(FilterConfig arg0) throws ServletException { ServletContext servletContex ...

  3. linux git pull/push时提示输入账号密码之免除设置

    1.先cd到根目录,执行git config --global credential.helper store命令 [root@iZ25mi9h7ayZ ~]# git config --global ...

  4. PAT 甲级 1027 Colors in Mars (20 分)

    1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...

  5. Letsencrypt SSL免费证书申请(Docker)

    最近需要SSL证书,又不想花钱买,正好看到linux基金会去年底上线了新的开源项目,免费推广SSL遂尝试. Let's Encrypt 介绍 Let’s Encrypt is a free, auto ...

  6. WebHttpRequest在sharepoint文档库中的使用

    写在前面 由于sharepoint服务器上的站点采用的域用户windows认证的方式登陆,而app项目虽然能够提供用户名和密码,但客户是不愿意在网络上这样传输的.所以给提供了使用ssl证书认证的方式. ...

  7. nodejs+mocha+supertest+chai进行测试(only demo)

    1.nodejs安装成功 (上一篇:brew install nodejs) 2.mocha安装成功 npm install -g mocha 解释: -g代表global,全局的意思.此处mocha ...

  8. python-单元测试优化,加入日志

    HttpRequests.py #-*- coding:utf-8 -*- import requests class HttpRequests(): def http_requests(self,u ...

  9. python初接触

    浑浑噩噩的过了3年多大学生涯,就借此开始下定决心好好的学好一门技术,为心中那个游戏梦而努力. 正式开课的第一天(也算不的吧,毕竟昨天老师也和我们讲了python课程的大纲内容).自我总结下今天的内容吧 ...

  10. scrollview嵌套recyclerview卡顿现象

    方式一xml: android:nestedScrollingEnabled="false" <android.support.v7.widget.RecyclerView ...