整理上次写的题目:

A:

For a positive integer n let's define a function f:

f(n) =  - 1 + 2 - 3 + .. + ( - 1)nn

Your task is to calculate f(n) for a given integer n.

Input

The single line contains the positive integer n (1 ≤ n ≤ 10^15).

题目简洁。可以看出规律。。。分下奇偶就可以了。

B:

B. OR in Matrix
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner:

 where  is equal to 1 if some ai = 1, otherwise it is equal to 0.

Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:

.

(Bij is OR of all elements in row i and column j of matrix A)

Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large.

Input

The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively.

The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1).

Output

In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print mrows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.

题目比较烦。

但是我们可以得出这样一个规律:先预设定所有数为1,然后按得出的答案去把数变为0.然后验证是否满足答案。。

明白这一点 就简单了。

 #include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
typedef long long ll;
using namespace std; int a[][];
int b[][];
int main()
{
int m,n;
cin>>m>>n;
for (int i=;i<=m;i++)
for (int j=;j<=n;j++) b[i][j]=;
for (int i=;i<=m;i++)
for (int j=;j<=n;j++)
cin>>a[i][j]; for (int i=;i<=m;i++)
for (int j=;j<=n;j++)
if (a[i][j]==){
for (int k=;k<=n;k++)
b[i][k]=;
for (int k=;k<=m;k++)
b[k][j]=;
} for (int i=;i<=m;i++)
for (int j=;j<=n;j++)
if (a[i][j]==)
{
int tmp=;
for (int k=;k<=n;k++)
tmp|=b[i][k];
for (int k=;k<=m;k++)
tmp|=b[k][j];
if (tmp==)
{
cout<<"NO";
return ;
}
} cout<<"YES"<<endl;
for (int i=;i<=m;i++){
for (int j=;j<=n;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
return ;
}
C:

 

同样很繁琐的题目,但是我们可以贪心之。

贪心策略:1,先计算字符串的一半值。。。比如abcbcc

对应的值应当是211112.我们发现对半分的字符串所需最少的步数是对称的。还有我们要计算出最少步数。这里具体见代码。

然后当p在左半部分是就只做左半部分。同理右半部份。。。我们不可能p<=(n+1)/2,去做右半部份。

然后抽象认为这样的题目:数组为1 2 3 0 2的数组。当p在某个位置时。求全部变为0最少的步数。。。

这里用贪心或者啥的。我用了一个比较巧的办法。

然后因为写的太繁琐。露了条件。。。一直WA。。真是菜

 #include<bits/stdc++.h>
using namespace std;
#define N 123456
string s;
int a[N];
int n,p; int main()
{
cin>>n>>p;
cin>>s;
for (int i=;i<s.size();i++){
int tmp1=abs(s[i]-s[n-i-]);
int tmp2;
if (s[i]>s[n-i-]) tmp2=abs(s[i]--s[n-i-]);
else tmp2=abs(s[n-i-]-s[i]-);
a[i+]=min(tmp1,tmp2);
} int mid=(n+)/;
int ans=0x3f3f3f; if (p<=mid)
{
int ans1=;
int tmpp=p;
for (int i=;i<=mid;i++)
if (a[i])
{
ans1+=a[i];
ans1+=abs(tmpp-i);
tmpp=i;
}
ans=min(ans1,ans); ans1=;
tmpp=p;
for(int i=mid;i>=;i--)
if (a[i])
{
ans1+=a[i];
ans1+=abs(tmpp-i);
tmpp=i;
}
ans=min(ans1,ans);
} else
{ int ans1=;
int tmpp=p;
for (int i=mid+;i<=n;i++)
if (a[i])
{
ans1+=a[i];
ans1+=abs(tmpp-i);
tmpp=i;
}
ans=min(ans1,ans);
ans1=;
tmpp=p;
for(int i=n;i>mid;i--)
if (a[i])
{
ans1+=a[i];
ans1+=abs(tmpp-i);
tmpp=i;
}
ans=min(ans,ans1);
} cout<<ans<<endl;
return ;
}

D题:不是原创。

我们可以这样处理。

每次枚举第I个数。并且默认为根节点。且权值最大。然后我们的目的是找到多少个其子树是满足max-min<=d;

这里用DFS就好了。

 #include<bits/stdc++.h>
#define N 12345
#define mod 1000000007
typedef long long ll;
using namespace std;
int a[N];
int con;
vector<int> mp[N];
int d; ll dfs(int p,int pre)
{
ll tot=;
for (int i=;i<mp[p].size();i++)
{
int v=mp[p][i];
if (pre==v||a[con]<a[v]||a[con]-a[v]>d||(a[con]==a[v]&&v<con)) continue;
tot=tot*(dfs(v,p)+)%mod;
}
return tot;
} int main()
{
int n;
cin>>d;
cin>>n;
for (int i=;i<=n;i++) cin>>a[i];
for (int i=;i<n;i++)
{
int x,y;
cin>>x>>y;
mp[x].push_back(y);
mp[y].push_back(x);
}
ll ans=;
for (int i=;i<=n;i++)
{
con=i;
ans=(ans+dfs(i,-))%mod;
}
cout<<ans;
}

E:继续补...不出来了。。。

还是忍不住看了题解。。

先说说自己的想法好了。。

解析:如果我们用二分做LIS 会发现我们做的事“字典序最小的LIS",怎么理解。。

比如 1 3 2 5.。我们会算出这样的3个数:1 2 5.

其实很多东西包含在这里。。

比如:我们预先算出每个数“对应多少个”。 比如 1 4 2 5 7 3 9

1 2 2 3 4 3 5

算出这样的数列

那么答案出来了 ai=4&&ai=2 是两个答案。 ai=5输出一种,ai=3不再LIS 里面。

然后代码就是这样了:

 #include<bits/stdc++.h>
using namespace std;
#define N 123456
int a[N],b[N],c[N];
int good[N];
int dp[N];
int now[N]; int main()
{
int n;
cin>>n;
for (int i=;i<=n;i++) cin>>a[i]; int t=;
for (int i=;i<=n;i++)
{
if (a[i]>b[t]) {b[++t]=a[i];dp[i]=t;}
else
{
int x=lower_bound(b+,b+t+,a[i])-b;
b[x]=a[i];
dp[i]=x;
}
} int mx=t; for (int i=n;i>=;i--)
if (dp[i]==mx||now[dp[i]+]>a[i])
{
good[i]=dp[i];
c[good[i]]++;
now[dp[i]]=max(now[dp[i]],a[i]);
} for (int i=;i<=n;i++)
{
if (c[good[i]]==) cout<<;
else if (c[good[i]]==) cout<<;
else cout<<;
}
return ;
}

Codeforces Round #277 (Div. 2)的更多相关文章

  1. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

  2. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  3. 【codeforces】Codeforces Round #277 (Div. 2) 解读

    门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...

  4. Codeforces Round #277 (Div. 2) E. LIS of Sequence DP

    E. LIS of Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/pr ...

  5. Codeforces Round #277 (Div. 2) D. Valid Sets 暴力

    D. Valid Sets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem ...

  6. Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心

    B. OR in Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/probl ...

  7. Codeforces Round #277 (Div. 2) A. Calculating Function 水题

    A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...

  8. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  9. codeforces水题100道 第十题 Codeforces Round #277 (Div. 2) A. Calculating Function (math)

    题目链接:www.codeforces.com/problemset/problem/486/A题意:求表达式f(n)的值.(f(n)的表述见题目)C++代码: #include <iostre ...

  10. Codeforces Round #277 (Div. 2 Only)

    A:SwapSort http://codeforces.com/problemset/problem/489/A 题目大意:将一个序列排序,可以交换任意两个数字,但要求交换的次数不超过n,输出任意一 ...

随机推荐

  1. 安装Google框架服务并突破Google Play下载限制

    请注明出处:http://www.cnblogs.com/killerlegend/p/3546235.html Written By KillerLegend 关于谷歌服务框架以及安装 安装前请先获 ...

  2. ListView与.FindControl()方法的简单练习 #2 -- ItemUpdting事件中抓取「修改后」的值

    原文出處  http://www.dotblogs.com.tw/mis2000lab/archive/2013/06/24/listview_itemupdating_findcontrol_201 ...

  3. SIMATIC IT HISTORIAN在烟用二醋酸纤维素生产中应用

    原文转载自:http://www.soft6.com/tech/5/54287.html 本文介绍了西门子MES核心产品SIMATIC IT HISTORIAN实时数据库及客户端工具在流程生产中的具体 ...

  4. 使用WIF实现单点登录Part IV —— 常见问题

    InvalidOperationException: ID1073: 尝试使用 ProtectedData API 解密 Cookie 时出现 CryptographicException (有关详细 ...

  5. python 序列化之JSON和pickle详解

    JSON模块 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类 ...

  6. wpf做的可扩展记事本

    记得有个winform利用反射做的可扩展笔记本,闲来无事,便用wpf也搞了个可扩展记事本,可用接口动态扩展功能,较简单,以便参考: 目录结构如下: MainWindow.xaml为主功能界面,Func ...

  7. sqlserver中查找长时间未提交事务

    无论是有意无意,如果事务在数据库中保持打开,则它会阻塞其他进程对修改后的数据进行操作.同样,对事务日志进行备份也只会截断不活动事务的那部分事务日志,所以打开的事务会导致日志变多(甚至达到物理限制),直 ...

  8. mysql索引合并:一条sql可以使用多个索引

    前言 mysql的索引合并并不是什么新特性.早在mysql5.0版本就已经实现.之所以还写这篇博文,是因为好多人还一直保留着一条sql语句只能使用一个索引的错误观念.本文会通过一些示例来说明如何使用索 ...

  9. hdu 1548 A strange lift

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Description There is a strange li ...

  10. IBM X3650 M4安装win 2008 Server操作指南

    由于IBM服务器是IBM原有的Linux系统,所以需要在此硬件上安装Win 2008 Server系统(以下简称win8),中间遇到了很多坑,在下面的描述中会阐述.以下是安装的整个步骤: 一.所需工具 ...