Maximum Multiple

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3985    Accepted Submission(s): 926

Problem Description

Given an integer n, Chiaki would like to find three positive integers x, y and z such that: n=x+y+z, x∣n, y∣n, z∣n and xyz is maximum.

Input

There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:

The first line contains an integer n (1≤n≤106).

Output

For each test case, output an integer denoting the maximum xyz. If there no such integers, output −1 instead.

Sample Input

3

1

2

3

Sample Output

-1

-1

1

题解:找规律,打个表就会发现,每个数的乘积的最大值都和3和4有关

打表:

#include<bits/stdc++.h>
#define ios1 ios::sync_with_stdio(0)
#define ios2 cin.tie(0)
#define LL long long
#define INF 0x3f3f3f3f
using namespace std; int main (){
int T, n;
scanf("%d", &T);
while(T--) {
for(int r = 1; r <= 50; r ++){
printf("n = %d\n", r);
for(int i = 1; i <= n; i++) {
if(r % i == 0) {
for(int j = 1; j <= n; j++) {
if(r % j == 0) {
for(int k = 1; k <= n; k++) {
if(r % k == 0){
if((i + j + k) == r){
int p = i * j * k;
printf("i = %d j = %d k = %d p = %d\n", i, j, k, p);
}
}
}
}
}
}
}
}
}
return 0;
}

AC代码:

#include<bits/stdc++.h>
#define ios1 ios::sync_with_stdio(0)
#define ios2 cin.tie(0)
#define LL long long
#define INF 0x3f3f3f3f
using namespace std; int main() {
int T;
LL n;
scanf("%d", &T);
while(T--) {
scanf("%lld", &n);
if(n % 3 == 0) {
LL k = n / 3;
printf("%lld\n", k * k * k);
}
else if(n % 4 == 0){
LL k = n / 4;
LL p = k * k * (n - 2 * k);
printf("%lld\n", p);
}
else printf("-1\n");
}
return 0;
}

Triangle Partition

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)

Total Submission(s): 2174    Accepted Submission(s): 1102
Special Judge

Problem Description

Chiaki has 3n points p1,p2,…,p3n. It is guaranteed that no three points are collinear.

Chiaki would like to construct n disjoint triangles where each vertex comes from the 3n points.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1≤n≤1000) -- the number of triangle to construct.

Each of the next 3n lines contains two integers xi and yi (−109≤xi,yi≤109).

It is guaranteed that the sum of all n does not exceed 10000.

Output

For each test case, output n lines contain three integers ai,bi,ci (1≤ai,bi,ci≤3n) each denoting the indices of points the i-th triangle use. If there are multiple solutions, you can output any of them.

Sample Input

1

1

1 2

2 3

3 5

Sample Output

1  2  3

题解:题中说明任意一组解即可,对横纵坐标排个序即可;

#include<bits/stdc++.h>
#define ios1 ios::sync_with_stdio(0)
#define ios2 cin.tie(0)
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 3100; struct node {
int x, y, id;
}arr[maxn]; bool cmp (node p, node q) {
if(p.x == q.x) return p.y < q.y;
return p.x < q.x;
} int main() {
int T, n;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
n = 3 * n;
for(int i = 1; i <= n; i++) {
scanf("%d%d", &arr[i].x, &arr[i].y);
arr[i].id = i;
}
sort(arr + 1, arr + 1 + n, cmp);
for(int i = 3; i <= n; i+=3){
printf("%d %d %d\n", arr[i-2].id, arr[i-1].id, arr[i].id);
}
}
return 0;
}

Distinct Values

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4796    Accepted Submission(s): 1629

Problem Description

Chiaki has an array of n positive integers. You are told some facts about the array: for every two elements ai and aj in the subarray al..r (li<jr), aiaj holds.

Chiaki would like to find a lexicographically minimal array which meets the facts.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains two integers n and m (1≤n,m≤105) -- the length of the array and the number of facts. Each of the next m lines contains two integers li and ri(1≤lirin).

It is guaranteed that neither the sum of all n nor the sum of all m exceeds 106.

Output

For each test case, output n integers denoting the lexicographically minimal array. Integers should be separated by a single space, and no extra spaces are allowed at the end of lines.

Sample Input

3
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4

Sample Output

1 2

1 2 1 2

1 2 3 1 1

#include<bits/stdc++.h>
using namespace std;
#define ios1 std::ios::sync_with_stdio(false)
#define ios2 std::cin.tie(0)
#define inf 0x3f3f3f3f
#define ll long long
const int maxn = 1e5 + 10;
int que[maxn], ans[maxn]; int main(){
int T, n, m;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m);
memset(que, 0, sizeof(que));
set<int>s;
for(int i = 1; i <= n; i++) {
s.insert(i);
que[i] = i;
}
int u, v;
while(m--) {
scanf("%d%d", &u, &v);
que[u] = max(que[u], v);
}
int left = 1;
for(int i = 1; i <= n; i++) {
if(i != 1) {
s.insert(ans[i-1]);
}
while(left <= que[i]) {
ans[left] = *s.begin();
s.erase(ans[left++]);
}
}
for(int i = 1; i < n; i++) {
printf("%d ", ans[i]);
}
printf("%d\n", ans[n]);
}
return 0;
}

2018 Multi-University Training Contest 1(部分题解)的更多相关文章

  1. 2018 Multi-University Training Contest 3(部分题解)

    Problem F. Grab The Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Ja ...

  2. 2018 Multi-University Training Contest 2(部分题解)

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  3. 2018 Multi-University Training Contest - Team 1 题解

    Solved A HDU 6298 Maximum Multiple Solved B HDU 6299 Balanced Sequence Solved C HDU 6300 Triangle Pa ...

  4. 2018 Nowcoder Multi-University Training Contest 2

    目录 Contest Info Solutions A. run D. monrey G. transform H. travel I. car J. farm Contest Info Practi ...

  5. 2016 Multi-University Training Contest 3 部分题解

    1001,只要枚举区间即可.签到题,要注意的是输入0的话也是“TAT”.不过今天补题的时候却WA了好几次,觉得奇怪.原来出现在判断条件那里,x是一个int64类型的变量,在进行(x<65536* ...

  6. 2016 Multi-University Training Contest 1 部分题解

    第一场多校,出了一题,,没有挂零还算欣慰. 1001,求最小生成树和,确定了最小生成树后任意两点间的距离的最小数学期望.当时就有点矛盾,为什么是求最小的数学期望以及为什么题目给了每条边都不相等的条件. ...

  7. 2016 Multi-University Training Contest 4 部分题解

    1001,官方题解是直接dp,首先dp[i]表示到i位置的种类数,它首先应该等于dp[i-1],(假设m是B串的长度)同时,如果(i-m+1)这个位置开始到i这个位置的这一串是和B串相同的,那么dp[ ...

  8. 2018 Nowcoder Multi-University Training Contest 1

    Practice Link J. Different Integers 题意: 给出\(n\)个数,每次询问\((l_i, r_i)\),表示\(a_1, \cdots, a_i, a_j, \cdo ...

  9. 2018 Nowcoder Multi-University Training Contest 5

    Practice Link A. gpa 题意: 有\(n\)门课程,每门课程的学分为\(s_i\),绩点为\(c_i\),要求最多删除\(k\)门课程,使得gpa最高. gpa计算方式如下: \[ ...

随机推荐

  1. 今天代码中接触到了一个新的东西。js的上下自动滚动,无缝对接。

    js的上下自动滚动,无缝对接.为什么会用到这个东西呢?因为我在做公司的官网项目的修改的时候.有一个产品介绍的页面,会有很多的产品出现在,中间部分的列表里.但是又不能够使用分页.所以我就在想如果,列表数 ...

  2. JAVA基础——Switch条件语句

    JAVA基础——switch 条件语句 switch语句结构: switch(表达式){ case值1: 语句体1: break: case值2: 语句体2: break: case值3: 语句体3: ...

  3. C语言编程入门之--第五章C语言基本运算和表达式-part1

    导读:程序要完成高级功能,首先要能够做到基本的加减乘除.本章从程序中变量的概念开始,结合之前学的输出函数和新介绍的输入函数制作简单人机交互程序,然后讲解最基础的加减法运算,自制简单计算器程序练手. 5 ...

  4. Activiti6系列(4)- 三个war包的数据源及密码修改

    一.activiti-app修改数据源和密码 1.使用sublimetext工具打开tomcat,方便进行配置文件的修改. 找到被解压的war包,activiti-app/WEB-INF/classe ...

  5. win10 我的电脑下面的六个文件夹的隐藏

      第一步   第二步     第三步 修改注册表,要隐藏那个文件夹,ThisPCPolicy 改为 "Hide" 修改我的文档的注册表值,使我的文档文件夹隐藏     <w ...

  6. xpath爬虫实例,爬取图片网站百度盘地址和提取码

    某套图网站,套图以封面形式展现在页面,需要依次点击套图,点击广告盘链接,最后到达百度网盘展示页面. 这一过程通过爬虫来实现,收集百度网盘地址和提取码,采用xpath爬虫技术 1.首先分析图片列表页,该 ...

  7. 正则表达式之Matcher类中group方法

    前言 同事把一个excel表给我,里面的数据大概有几千的样子吧.自己需要把里面的数据一个一个拿出来做一个http请求,对得到的结果进行过滤,然后再写到上面去.这是就涉及到用脚本来进行操作了,于是自己搞 ...

  8. 前端数据双向绑定原理:Object.defineProperty()

    Object.definedProperty方法可以在一个对象上直接定义一个新的属性.或修改一个对象已经存在的属性,最终返回这个对象. Object.defineProperty(obj, prop, ...

  9. JMM内存模型详解(一)

    本文开始死磕JMM(Java内存模型)由于知识点较多,分来写 该文为JMM第一篇 技术往往是枯燥的,本文文字较多 1. JMM是什么? 其实JMM很好理解,我简单的解释一下,在Java多线程中我们经常 ...

  10. 记基于docker+gunicorn部署sanic项目遇到的很多很多坑

    前言: 最近有个项目需要上线,是python中sanic网络异步框架写的,并且要求使用docker+nginx来部署项目实现负载均衡,于是乎百度了sanic项目部署,基本上都是基于docker+gun ...