A:暴力弄就好,怎么方便怎么来。      

B:我们知道最多加10次,

然后每次加1后我们求能移动的最小值,大概O(N)的效率。

 #include<bits/stdc++.h>

 using namespace std;
#define inf 0x3f3f3f
#define N 1234567 string pan(string s)//求能移动的最小字符串
{
string tmp=s;
for (int i=;i<s.size();i++)
{
string k="";
for (int j=i+;j<s.size();j++)
k+=s[j];
for (int j=;j<=i;j++)
k+=s[j];
tmp=min(tmp,k);
}
return tmp;
} int main()
{
int n;
cin>>n;
string s; cin>>s;
string ans=s;
ans=min(ans,pan(s));
for (int i=;i<=;i++)
{
for (int j=;j<s.size();j++)
{
if (s[j]=='') s[j]='';
else s[j]+=;
}
ans=min(ans,pan(s));
} cout<<ans; return ;
}

C:其实题目本意是1000*1000的矩阵,改成100*100,就有各种乱过了。

我的做法:先构造一个n*m的矩阵a[n,m];

加入s[i][j]>s[i-1][j] a[i][j]=1;

if (s[i][j]<s[i-1][j]) a[i][j]=-1;

else a[i][j]=0;

具体操作是:如果a[i][j]==-1时,说明其值小于上一行的数,于是这行就改变。去掉。

我们并用一维数组保存状态。

O(n*m)的 效率了

 #include<bits/stdc++.h>

 using namespace std;
#define inf 0x3f3f3f
#define N 1234567 int n,m;
string s[];
int a[][];
int b[]; int main()
{
cin>>n>>m;
for (int i=;i<=n;i++) cin>>s[i];
for (int i=;i<=n;i++)
{
for (int j=;j<m;j++){
if (s[i][j]>s[i-][j]) a[i][j+]=;
else if (s[i][j]<s[i-][j]) a[i][j+]=-;
}
} int ans=;
for (int j=;j<=m;j++)
{
int flag=;
for (int i=;i<=n;i++)
if (a[i][j]==-&&b[i]==)//说明这一行前面比较的状态
{
flag=;
ans++;
break;
}
if (!flag)
{
for (int i=;i<=n;i++)
if (a[i][j]==) b[i]=;
}
} cout<<ans; return ;
}

E:鉴于一直在想E,发现set用法不太会。

其实本省做法也有各种问题。

于是看了前人代码:

大概思路:

先把n,m个问题和人数全加入vector<node>数组

node 记入左区间L,右区间R,还有一个位置pos,以及type类型代表其实询问,还是能选择的人。

自定义排序,以及构造。。

排序的关键是先按L排序,再按type 排序

然后对于是询问我们二分查找在set里面,否侧插入在set中,

还有保存k的状态,如果k==0的话 就从set中删去。

这里用到贪心的方法,前面我们已排好顺序,所以对于询问l[i],r[i],我们查找的时候一定是在L<=l[i]z中找的,

且找的一定是R最接近r[i]的值。这里好好体会一下。

描述的比价混乱:

具体代码应该了解这种思路

 #include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<set>
#include<vector> using namespace std;
typedef long long ll;
#define N 234567
#define mp make_pair
struct node
{
int l,r,id,type;
node(int l=,int r=,int id=,int type=):l(l),r(r),id(id),type(type){} bool operator < (node b)const{
if (l==b.l) return type<b.type;
return l<b.l;
}
}; int n,m;
int lt[N],rt[N];
vector<node> v;
int k[N],ans[N]; set<pair<int,int> > s;
set<pair<int,int> >::iterator it; int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
v.push_back(node(x,y,i,));
} scanf("%d",&m);
for (int i=;i<=m;i++)
{
scanf("%d%d%d",&lt[i],&rt[i],&k[i]);
v.push_back(node(lt[i],rt[i],i,)); } sort(v.begin(),v.end());
for (int i=;i<v.size();i++)
{
if (v[i].type==)
s.insert(mp(v[i].r,v[i].id)); else
{
it=s.lower_bound(mp(v[i].r,));
if (it==s.end())
{
puts("NO");
return ;
}
int tmp=it->second;
ans[v[i].id]=tmp;
s.erase(it);
k[tmp]--;
if (k[tmp]) s.insert(mp(rt[tmp],tmp));
} }
puts("YES");
for (int i=;i<=n;i++)
printf("%d ",ans[i]); return ;
}

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

  1. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  2. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  3. Codeforces Round #283 (Div. 2) C. Removing Columns 暴力

    C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #283 Div.2 D Tennis Game --二分

    题意: 两个人比赛,给出比赛序列,如果为1,说明这场1赢,为2则2赢,假如谁先赢 t 盘谁就胜这一轮,谁先赢 s 轮则赢得整个比赛.求有多少种 t 和 s 的分配方案并输出t,s. 解法: 因为要知道 ...

  6. codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)

    题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...

  7. codeforces 497b// Tennis Game// Codeforces Round #283(Div. 1)

    题意:网球有一方赢t球算一场,先赢s场的获胜.数列arr(长度为n)记录了每场的胜利者,问可能的t和s. 首先,合法的场景必须: 1两方赢的场数不一样多. 2赢多的一方最后一场必须赢. 3最后一场必须 ...

  8. Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题

    B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. C# 程序开始主要是写类和方法 的基本步骤和调用方法

    主程序的使用方式以及调用方法字段.属性.方法 using System; using System.Collections.Generic; using System.Linq; using Syst ...

  2. 基于OWIN WebAPI

    http://www.cnblogs.com/Irving/p/4607104.html http://www.cnblogs.com/xishuai/p/aspnet-webapi-owin-oau ...

  3. UICollectionView [NSIndexPath section]: message sent to deallocated instance

    在UICollectionView上加UITapGestureRecognizer手势时,点击哪都报 [NSIndexPath section]: message sent to deallocate ...

  4. Ruby使用gets的错误:gets得到的有'\n',需要使用chomp去掉

    gets方法得到的字符串包含一个“\n”回车符,所以我们需要继续使用chomp方法把"\n"回车符去掉

  5. Android开发遇到的异常及解决办法

    Android开发遇到的错误及解决方法1. Unable to resolve target 'android-7' 解决方案: 修改工程目录下的default.properties文件里的内容tar ...

  6. html5 shiv

    使用html5标签吧!ie6.ie7.ie8不支持怎么办?它的原理是如此的简单:    1.document.createElement("ele");  // js虚拟创建一个元 ...

  7. golang反射初试

    golang反射来自Go AST(Abstract Syntax Tree). reflect操作更多像traverse AST. t := reflect.TypeOf(obj) 使用TypeOf( ...

  8. golang的内存模型与new()与make()

    要彻底理解new()与make()的区别, 最好从内存模型入手. golang属于c family, 而c程序在unix的内在模型: |低地址|text|data|bss|heap-->|unu ...

  9. sharepoint 2010 找不到搜索不到ad里的用户

    前提条件: 1.这个用户是在ad中存在的. 2.这个用户也同步到了userprofile中. 问题现象: 在sharepoint的人员选择器中,搜索不到已经添加的用户. 可能原因: 1.有人说需要将 ...

  10. C Primer Plus学习笔记(二)

    1. C的左值用是指用于标志一个特定的数据对象的名字或表达式.“数据对象”是泛指数据存储的术语. 赋值运算符的左边应该是以个可以修改的左值. 右值是指可赋给可修gia的左值的量.右值可以是常量.变量或 ...