OUC_Summer Training_ DIV2_#9 719
其实自己只会做很简单的题,有时都不想写解题报告,觉得不值得一写,但是又想到今后也许就不会做ACM了,能留下来的东西只有解题报告了,所以要好好写,很渣的题也要写,是今后的纪念。
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
Input
The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account.
Output
In a single line print an integer — the maximum state of the bank account that Ilya can get.
Sample Input
2230
2230
-10
0
-100003
-10000
输入一个整数(可正可负)可以改变最后一位数或者倒数第二个数,使这个数最大。
#include<stdio.h>
int main()
{
int acc;
int new1,new2;
scanf("%d",&acc);
if(acc >= )printf("%d",acc);
else
{
new1 = acc/;
new2 = new1/ * +(acc - new1 * );
if(new1 > new2)printf("%d",new1);
else printf("%d",new2);
}
return ;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), thatsi = si + 1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
Input
The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n).
Output
Print m integers — the answers to the queries in the order in which they are given in the input.
Sample Input
......
4
3 4
2 3
1 6
2 6
1
1
5
4
#..###
5
1 3
5 6
1 5
3 6
3 4
1
1
2
2
0
#include<stdio.h>
#include<string.h>
char a[];
int b[];
int main()
{ int n,x,y,i,j,len;
scanf("%s",a);
len = strlen(a);
for(i = ;i < len;i++)
{
if(a[i-]== a[i])
b[i] = b[i - ]+;
else
b[i] = b[i - ];
}
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&x,&y);
printf("%d\n",b[y-] - b[x-] );
}
return ;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.
He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum.
The beauty of a 2n × 2n-sized matrix is an integer, obtained by the following algorithm:
- Find the maximum element in the matrix. Let's denote it as m.
- If n = 0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2n - 1 × 2n - 1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices.
As you can see, the algorithm is recursive.
Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.
Input
The first line contains integer 4n (1 ≤ 4n ≤ 2·106). The next line contains 4n integers ai (1 ≤ ai ≤ 109) — the numbers you need to arrange in the 2n × 2n-sized matrix.
Output
On a single line print the maximum value of the beauty of the described matrix.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.
Sample Input
1
13
13
4
1 2 3 4
#include<iostream>
#include<algorithm>
using namespace std;
long long int a[];
long long int sum = ;
int main()
{ int N,n,i,j,k,m = ;
cin >> N;
n = N;
while(n != )
{
n = n/;
m++;
}
for(i = ;i < N;i++)
{
cin >> a[i];
sum += a[i];
}
sort(a,a+N);
for(i = N/;i >= ;i= i/)
{
for(j = N-;j >= N--i+;j--)
sum += a[j];
}
cout << sum;
return ; }
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
A median in an array with the length of n is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2, 6, 1, 2, 3) is the number 2, and a median of array (0, 96, 17, 23) — the number 17.
We define an expression as the integer part of dividing number a by number b.
One day Vasya showed Petya an array consisting of n integers and suggested finding the array's median. Petya didn't even look at the array and said that it equals x. Petya is a very honest boy, so he decided to add several numbers to the given array so that the median of the resulting array would be equal to x.
Petya can add any integers from 1 to 105 to the array, including the same numbers. Of course, he can add nothing to the array. If a number is added multiple times, then we should consider it the number of times it occurs. It is not allowed to delete of change initial numbers of the array.
While Petya is busy distracting Vasya, your task is to find the minimum number of elements he will need.
Input
The first input line contains two space-separated integers n and x (1 ≤ n ≤ 500, 1 ≤ x ≤ 105) — the initial array's length and the required median's value. The second line contains n space-separated numbers — the initial array. The elements of the array are integers from 1 to 105. The array elements are not necessarily different.
Output
Print the only integer — the minimum number of elements Petya needs to add to the array so that its median equals x.
Sample Input
3 10
10 20 30
1
3 4
1 2 3
4
Hint
In the first sample we can add number 9 to array (10, 20, 30). The resulting array (9, 10, 20, 30) will have a median in position , that is, 10.
In the second sample you should add numbers 4, 5, 5, 5. The resulting array has median equal to 4.
有一个数组(任意顺序要从小到大排序)和一个数,改变这个数组,要使这个数处于数组中间位置,输出改变的次数。
交了不对,也把代码贴上,再贴几个大神的代码。
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[] = {-};
int n,i,j,m,num = ,x,y;
cin >> n >> m;
for(i = ;i <= n;i++)
{
cin >> a[i];
}
sort(a,a+n);
for(i = ;i <= n;i++)
{
if(a[i] <= m)
{
if(a[i] == m && i == (n+)/)
{
cout << << endl;
return ;
}
else continue;
}
else break;
}
x = i - ;
y = n - i + ;
num = (x < y)? y - x:x - y;
if((n + num)/ == i)
cout << num ;
else cout << num+;
return ;
}
#include<stdio.h>
int data[]; int d(double x); int main(void)
{
int n,x;
while(scanf("%d%d",&n,&x)!=-)
{
int bigger=;
int smaller=;
int counter=;
for(int i=;i<n;i++)
{
scanf("%d",&data[i]);
if(data[i]>x)
{
bigger++;
}
if(data[i]<x)
{
smaller++;
}
if(data[i]==x)
{
counter++;
}
}
if(smaller<d(n)&&smaller+counter>=d(n))
{
printf("0\n");
}
else if(smaller<counter+bigger)
{
printf("%d\n",bigger-smaller-counter);
}
else
{
printf("%d\n",smaller-bigger+-counter);
}
//printf("bigger: %d, smaller: %d, counter: %d, \n",bigger,smaller,counter);
}
return ;
} int d(double x)
{
return (int)(x+)*1.0/2.0;
}
OUC_Summer Training_ DIV2_#9 719的更多相关文章
- OUC_Summer Training_ DIV2_#16 725
今天做了这两道题真的好高兴啊!!我一直知道自己很渣,又贪玩不像别人那样用功,又没有别人有天赋.所以感觉在ACM也没有学到什么东西,没有多少进步.但是今天的B题告诉我,进步虽然不明显,但是只要坚持努力的 ...
- OUC_Summer Training_ DIV2_#13 723afternoon
A - Shaass and Oskols Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- OUC_Summer Training_ DIV2_#12(DP1) 723
这一次是做练习,主要了解了两个算法,最大子矩阵和,最长上升子序列. 先看题好啦. A - To The Max Time Limit:1000MS Memory Limit:32768KB ...
- OUC_Summer Training_ DIV2_#14 724
又落下好多题解啊...先把今天的写上好了. A - Snow Footprints Time Limit:1000MS Memory Limit:262144KB 64bit IO F ...
- OUC_Summer Training_ DIV2_#2之解题策略 715
这是第一天的CF,是的,我拖到了现在.恩忽视掉这个细节,其实这一篇只有一道题,因为这次一共做了3道题,只对了一道就是这一道,还有一道理解了的就是第一篇博客丑数那道,还有一道因为英语实在太拙计理解错了题 ...
- OUC_Summer Training_ DIV2_#7 718
是18号做的题啦,现在才把报告补上是以前不重视报告的原因吧,不过现在真的很喜欢写报告,也希望能写一些有意义的东西出来. A - Dragons Time Limit:2000MS Memory ...
- OUC_Summer Training_ DIV2_#11 722
企鹅很忙系列~(可惜只会做3道题T_T) A - A Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d &am ...
- OUC_Summer Training_ DIV2_#5
这是做的最好的一次了一共做了4道题 嘻嘻~ A - Game Outcome Time Limit:2000MS Memory Limit:262144KB 64bit IO For ...
- OUC_Summer Training_ DIV2_#4之数据结构
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26100#problem/A A - A Time Limit:1000MS Me ...
随机推荐
- Linux JDK升级
一.jdk1.4卸载 Redhat Enterprise 5 中自带安装了jdk1.4,在安装jdk1.6前,把jdk1.4卸载: 1. 首先查看系统自带的JDK版本: [root@linux ~]# ...
- js之数据类型(对象类型——构造器对象——数组2)
一.数组空位与undefined 数组空位:数组的某一个位置没有任何值 产生空位的原因:数组中两个逗号之间不放任何值:用new Array()的方法,参数里是个数字:通过一个不存在的下标去增加数组:增 ...
- vue项目 时间戳转 格式
项目用了 element UI的日期插件,修改时 时间回显不了,打印出来是换行了,因此要转换 changeTime(value){ let date = new Date(value); let y ...
- Redis总结2
一.Redis效率高的原因 众所周知,Redis常用来做缓存,从而提高项目QPS(每秒查询率).QPS = 并发量 / 平均响应时间 然而其效率高的原因包含但不仅限于如下几点: 1.Redis基于内存 ...
- maven 父子工程打包 并且上传linux服务器
先对父工程进行 mvn clean 再对子工程执行 install wagon:upload-single wagon:sshexec 使用wagon前提: 本地maven 的settings.xml ...
- 解决IDEA报错Could not autowire. There is more than one bean of 'xxx' type
更新项目之后IDEA突然出现了这样的报错信息.显示Could not autowire. There is more than one bean of 'xxx' type.这个错误的意思是xxx类型 ...
- Windows去除开始菜单图标背景
1.开始菜单图标右键找到目标程序的存储目录. 2.删除目录下的目标程序名+.VisualElementsManifest.xml的文件. 3.开始菜单图标右键找到图标的存储目录,取消开始屏幕固定并删除 ...
- qt tableview中如何添加右键菜单且不可编辑单元格
QTableView是一个比较实用的类,下面教给大家如何在QTableView中添加右键菜单. #include <QMenu>#include <QAction> QTabl ...
- Cowrie蜜罐部署教程
0.蜜罐分类: 低交互:模拟服务和漏洞以便收集信息和恶意软件,但是攻击者无法和该系统进行交互: 中等交互:在一个特有的控制环境中模拟一个生产服务,允许攻击者的部分交互: 高交互:攻击者可以几乎自由 ...
- 【转】Linux设置和查看环境变量的方法
转: http://www.jb51.net/LINUXjishu/77524.html 1. 显示环境变量HOME $ echo $HOME /home/redbooks 2. 设置一个新的环境变量 ...