解题思路:就是求数 n 对应的二进制数中有多少个 1

#include <iostream>
#include<cstdio>
using namespace std; int main(){
int n;
cin>>n;
int ans = ;
// while(n){//这也是一种好的方法
// n = n&(n-1);
// ++ans;
// } while(n){
if(n&) ++ans;
n>>=;
}
cout<<ans<<endl;
return ;
}

解题思路:对(strength, i, j)按照strength进行递减排序,从左到右进行遍历,用b[N]表示i和j有关系!

如果发现b[i]或者b[j]有关系了,则跳过这个strength, 否则b[i] =j, b[j] = i;

#include <iostream>
#include <algorithm>
#include<cstdio>
using namespace std; struct node{
int x;
int i, j;
}a[]; int b[]; bool cmp(node a, node b){
return a.x > b.x;
} int main(){
int x, n;
int c = ;
cin>>n;
for(int k=; k<=*n; ++k){
for(int kk=; kk<k; ++kk){
cin>>x;
a[c].x = x;
a[c].i = k;
a[c++].j = kk;
}
}
sort(a, a+c, cmp);
int cnt = ;
for(int i=; i<c; ++i){
if(!b[a[i].i] && !b[a[i].j]){
b[a[i].i] = a[i].j;
b[a[i].j] = a[i].i;
++cnt;
}
if(cnt == n) break;
}
for(int i=; i<=*n; ++i){
if(i!=) cout<<" ";
cout<<b[i];
}
cout<<endl;
return ;
}

解题思路:

 

我们可以发现这样的一个规律:

(1)首先b一定要小于a,否则无论如何曲线也无法通过(a,b);

(2)设int k=a/b, 如果k为奇数,说明这个点在上图的绿色的线上, 没关系,我们让 k+=1;这样的话一定有(0,0), (a,b)这两点确定的直线的

斜率1/k介于(1/(k-1),  1/(k+1))之间,那么我们可以通过缩小(或者放大)X的值,使得第 k/2 个周期块 斜率为-1的那条边经过(a, b)。此时

的X值就是最小的!

(3)如果(a,b)在第 k/2 个周期块 斜率为-1的那条边上,那么这条边与X轴的交点就是(a+b, 0), 从(0, 0)到(a+b, 0)一共经过了 k/2个周期,

所以 X = (a+b)*1.0/(k/2 * 2)

(4)唉....想的这么明白,容易吗.....

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<cmath>
using namespace std; int main(){
int a, b;
cin>>a>>b;
if(b>a) {
cout<<-<<endl;
} else {
int k = a/b;
if(k&) ++k;
printf("%.12lf\n", (a+b)*1.0/k);
}
return ;
}

解题思路:如果某个数a[i]乘以x, 必定会导致a[i]的二进制的长度增大。

首先求出或运算的前缀和后缀,然后对每个a[i]操作如下: a[i]*=x^k(x的k次方); 最后找到a[i]|pref[i-1]|suff[i+1]的最大值!

其实可以优化一处,就是a[i]|pref[i-1]|suff[i+1]的最大值一定对应二进制长度最大的a[i]; 可通过log(a[i])+1求得二进制长度!

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<cmath>
#define N 200010
using namespace std; __int64 a[N];
__int64 pref[N];
__int64 suff[N]; int n, k, x; int main(){
scanf("%d%d%d", &n, &k, &x);
long long maxN = ;
for(int i=; i<=n; ++i)
scanf("%I64d", &a[i]);
long long xk = (long long)(pow((double)x, (double)k) + 0.5);
for(int i=; i<=n; ++i){
pref[i] = pref[i-] | a[i];
suff[n-i+] = suff[n-i+] | a[n-i+];
} for(int i=; i<=n; ++i){
long long num = a[i]*xk | pref[i-] | suff[i+];
if(maxN < num)
maxN = num;
}
printf("%I64d\n", maxN);
return ;
}

codeforces Round #320 (Div. 2) C. A Problem about Polyline(数学) D. "Or" Game(暴力,数学)的更多相关文章

  1. Codeforces Round #367 (Div. 2) C. Hard problem

    题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...

  2. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  3. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  4. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C C Problem about Polyline 数学

                                                                           C. A Problem about Polyline   ...

  5. [Codeforces] Round #320 (Div.2)

    1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria ...

  6. codeforces 578a//A Problem about Polyline// Codeforces Round #320 (Div. 1)

    题意:一个等腰直角三角形一样的周期函数(只有x+轴),经过给定的点(a,b),并且半周期为X,使X尽量大,问X最大为多少? 如果a=b,结果就为b 如果a<b无解. 否则,b/(2*k*x-a) ...

  7. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline(数学)

    题目中给出的函数具有周期性,总可以移动到第一个周期内,当然,a<b则无解. 假设移动后在上升的那段,则有a-2*x*n=b,注意限制条件x≥b,n是整数,则n≤(a-b)/(2*b).满足条件的 ...

  8. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp

    C. Weakness and Poorness Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  9. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心

    B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...

随机推荐

  1. Java_类似java.lang.VerifyError: Expecting a stackmap frame at branch target 22 in method的解决方法

    报异常的方法内使用了Java 7的新特性:自动资源释放,类似于try(){},即在try后面跟一括号,在括号里面对一些资源赋值,try里面的代码块执行完毕之后会自动释放try后面的括号中声明的资源. ...

  2. sublime Text 3 字体

    1,Comic Sans Ms 2,DejaVu Sans Mono 3,microsoft yahei(微软雅黑) 4,Microsoft Yahei UI(微软雅黑增强版) 5,Ubuntu Mo ...

  3. Python之路第一课Day8--随堂笔记(socket 承接上节---网络编程)

    本节内容 Socket介绍 Socket参数介绍 基本Socket实例 Socket实现多连接处理 通过Socket实现简单SSH 通过Socket实现文件传送 作业:开发一个支持多用户在线的FTP程 ...

  4. js实现div居中

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. java并发编程(十六)happen-before规则

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17348313 happen-before规则介绍 Java语言中有一个"先行发生 ...

  6. Proxy

    Proxy: Script: http://apgutmg01:8080/array.dll?Get.Routing.Script Server: apgutmg01 Port: 8080

  7. Android中SQLite数据库小计

    2016-03-16 Android数据库支持 本文节选并翻译<Enterprise Android - Programing Android Database Applications for ...

  8. [Voice communications] 声道的转换

    本系列文章主要是介绍 Web Audio API 的相关知识,以及 web语音通信 中会遇到的一些问题,阐述可能存在错误,还请多多斧正! 很多粤语剧都提供了两个声道,一个左声道为粤语,一个右声道有国语 ...

  9. 扫描仪API接入大全:Twain, WIA 或 两者不具有.[换个思路 春暖花开]

    最近做和扫描仪接入的扫描应用程序,深深感觉到了来自底层设备和WINDOWS协议的恶意.软件专业,对计算机深层次通知机制和协议,以及与之相连接的机器的接入协议和一些参数,当时并木有认真学习和了解,前一阵 ...

  10. Linux 定时任务

    200 ? "200px" : this.width)!important;} --> 介绍 本篇主要介绍Linux定时任务命令crontab的用法,crontab是定时任务 ...