当前位置: 首页 > news >正文

嘉兴企业网站wordpress目录插件

嘉兴企业网站,wordpress目录插件,网络营销宏观环境有哪些,昆明搜索引擎的关键词优化题目传送门 题目难度:普及/提高一 题面翻译 今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏。 贝茜让 N N N ( 1 ≤ N ≤ 1 0 5 1\leq N\leq 10^5 1≤N≤105) 头奶牛坐成一个圈。除了 1 1 1 号与 N N N 号奶牛外&#xff0…

题目传送门
题目难度:普及/提高一

题面翻译

今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏。

贝茜让 N N N ( 1 ≤ N ≤ 1 0 5 1\leq N\leq 10^5 1N105) 头奶牛坐成一个圈。除了 1 1 1 号与 N N N 号奶牛外, i i i 号奶牛与 i − 1 i-1 i1 号和 i + 1 i+1 i+1 号奶牛相邻。 N N N 号奶牛与 1 1 1 号奶牛相邻。农夫约翰用很多纸条装满了一个桶,每一张包含了一个不一定是独一无二的 1 1 1 1 0 6 10^6 106 的数字。

接着每一头奶牛 i i i 从桶中取出一张纸条 A i A_i Ai。每头奶牛轮流走上一圈,同时拍打所有手上数字能整除在自己纸条上的数字的牛的头,然后坐回到原来的位置。牛们希望你帮助他们确定,每一头奶牛需要拍打的牛的数量。

题目描述

It’s Bessie’s birthday and time for party games! Bessie has instructed the N (1 <= N <= 100,000) cows conveniently numbered 1…N to sit in a circle (so that cow i [except at the ends] sits next to cows i-1 and i+1; cow N sits next to cow 1). Meanwhile, Farmer John fills a barrel with one billion slips of paper, each containing some integer in the range 1…1,000,000.

Each cow i then draws a number A_i (1 <= A_i <= 1,000,000) (which is not necessarily unique, of course) from the giant barrel. Taking turns, each cow i then takes a walk around the circle and pats the heads of all other cows j such that her number A_i is exactly

divisible by cow j’s number A_j; she then sits again back in her original position.

The cows would like you to help them determine, for each cow, the number of other cows she should pat.

输入格式

* Line 1: A single integer: N

* Lines 2…N+1: Line i+1 contains a single integer: A_i

输出格式

* Lines 1…N: On line i, print a single integer that is the number of other cows patted by cow i.

样例 #1

样例输入 #1

5 
2 
1 
2 
3 
4

样例输出 #1

2 
0 
2 
1 
3

提示

The 5 cows are given the numbers 2, 1, 2, 3, and 4, respectively.

The first cow pats the second and third cows; the second cows pats no cows; etc.

题目分析:由于本题纯暴力枚举会炸的,优化解法:统计每个数字 Ai 出现的次数。对于每头奶牛 i枚举 Ai 的所有因数 并统计出现的次数。时间复杂度:O(NM)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;int ans[N],cnt[N],a[N]; 
int n;ll read()
{ll s=0,f=1;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}while (ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}return s*f;
}int main() {n = read();for(int i = 1; i <= n; i++) {a[i] = read();cnt[a[i]]++;}int t = 0;for(int i = 1; i <= n; i++){t = 0;for(int j = 1; j <= a[i] / j; j++){if(a[i] % j == 0) {t += cnt[j];if(j != a[i] / j) t += cnt[a[i] /  j];}} ans[i] = t - 1;}for(int i = 1; i <= n; i++) cout<<ans[i]<<endl;return 0;
}

http://www.yayakq.cn/news/141581/

相关文章:

  • 如果快速做网站网站建设仟金手指专业15
  • wordpress模板 图片站无锡网站制作方案
  • 青海保险网站建设公司上海网站高端定制
  • 专业的企业网站制作利用图床做网站
  • 合肥做网站推广的公司wordpress 列表排序
  • 常州个人做网站高端电商设计公司
  • 十堰网站建设培训学校网页制作怎么插视频
  • 电商网站销售数据分析重庆最新消息数据
  • 建站行业有哪些公司软装设计风格
  • 报价网站制作做网站的注意什么
  • 19年做网站还能赚钱徐州峰华网架公司
  • 网站seo综合公司做企业网站一般要多少钱
  • 做网站还是app好字体设计在线生成免费
  • 公司网站大全05网数学书答案
  • 找客户资源的网站建设银行贷款官方网站
  • 在阿里巴巴上做网站有效果吗建设部网站官网证书编号
  • 盐城网站建设价位智能建造师证书的含金量
  • 那个网站能找到人洛阳青峰网络
  • 过年做那个网站致富烟台装修行业网站建设方案
  • 洛阳做网站找哪家好免费网站源码html
  • 广州网站建设 易点网页注册qq
  • 万网主机怎么上传网站吗清迈城市建设网站
  • 购物网站开发毕业设计开题报告云龙微网站开发
  • 网站怎么进入网站界面设计技巧
  • 网站开发能赚钱吗企业站群cms
  • 中兴通讯的网站建设分析游戏排行
  • 网站建设 合肥怎么建立国外网站
  • 鸿邑科技 网站建设网站建设解决方案ppt模板
  • 深圳品牌网站建设服务南昌企业网站开发公司
  • 做的网站打开显示无标题ps做的网站稿怎么做成网站