数字反转

小模拟

 #include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int i,n;
char a[];
scanf("%s",&a);
n=strlen(a);
int t1=;
int t2=;
if (a[]=='-') {
printf("-");
t1++;
}
t2=n-;
for(i=n-;i>=;i--) if(a[i]=='')
t2--;
else break;
for(i=t2;i>=t1;i--) cout<<a[i];
return ;
}

数字反转

统计单词数

将待匹配字符串前后加空格,样本字符串前后加空格,这样无脑find就可以找出所有单词

 #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
string s,sf;
int t;//计数器;
int main(){
getline(cin,sf);
getline(cin,s);
int j;
for(j=;j<=sf.size();j++)sf[j]=tolower(sf[j]);
for(j=;j<=s.size();j++)s[j]=tolower(s[j]);
sf=' '+sf+' ';
s=' '+s+' ';
int posi=-;
int fpos=;
if(s.find(sf)==string::npos){cout<<"-1"; return ;}
fpos=s.find(sf);
while(s.find(sf,posi+)!=string::npos){
posi=s.find(sf,posi+);
t++;
}
cout<<t<<" "<<fpos;
return ;
}

统计单词数

瑞士轮

按照题目要求排序,每次模拟完都要排一次序。

直接sort会T

原本有序的序列,比赛完积分只加0或1,仍然是有序的,此时用归并排序只要O(n)复杂度。

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mxn=;
int n,r,q;
struct node{
int pw;
int score;
int num;
}a[mxn],w[mxn],f[mxn];//所有人 胜者 败者
int cmp(node a,node b){
if(a.score!=b.score) return a.score>b.score;
return a.num<b.num;
}
int main(){
scanf("%d%d%d",&n,&r,&q);
n=n*;
int i,j;
for(i=;i<=n;i++){
scanf("%d",&a[i].score);
}
for(i=;i<=n;i++){
scanf("%d",&a[i].pw);
a[i].num=i;
}
sort(a+,a+n+,cmp); for(i=;i<=r;i++){
for(j=;j<=n;j+=){
if(a[j].pw>a[j+].pw){
w[(j+)>>]=a[j];
f[(j+)>>]=a[j+];
}
else{
w[(j+)>>]=a[j+];
f[(j+)>>]=a[j];
}
w[(j+)>>].score++;
}
merge(w+,w+n/+,f+,f+n/+,a+,cmp);
}
printf("%d\n",a[q].num);
return ;
}

表达式的值

一边用栈计算表达式,计算过程中DP(其实是递推)

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mod=;
const int mxn=;
int f[mxn][],ntp=;
int n;
char st[mxn];int ctop=;
char s[mxn];
int cmp(char x){
if(!ctop)return ;
if(st[ctop]=='(')return ;
if(st[ctop]=='*')return ;
if(x=='*')return ;
if(st[ctop]=='+')return ;
return ;
}
void clc(char x){
int xa=f[ntp][],xb=f[ntp--][];//0 1
int ya=f[ntp][],yb=f[ntp--][];//0 1
int resa=,resb=;
if(x=='+'){
(resa+=xa*ya)%=mod;
(resb+=xa*yb)%=mod;
(resb+=xb*yb)%=mod;
(resb+=xb*ya)%=mod;
}
else{
(resb+=(xb*yb))%=mod;
(resa+=xa*yb+xb*ya)%=mod;
(resa+=xa*ya)%=mod;
}
f[++ntp][]=resa;
f[ntp][]=resb;
return;
}
int main(){
scanf("%d",&n);
scanf("%s",s+);
s[]='(';
s[++n]=')';
int i,j;
for(int i=;i<=n;i++){
// printf("%d %c\n",i,s[i]);
// for(j=1;j<=4;j++)printf("%d %d\n",f[j][0],f[j][1]);
// for(j=1;j<=4;j++)printf("%c ",st[j]);
// printf("\n");
if(s[i]=='('){
st[++ctop]=s[i];
continue;
}
if(s[i-]!=')'){ f[++ntp][]=;
f[ntp][]=;
}
if(s[i]=='+'){
while(cmp(st[ctop]))clc(st[ctop--]);
st[++ctop]=s[i];
}
else if(s[i]=='*'){
while(cmp(st[ctop]))clc(st[ctop--]);
st[++ctop]=s[i];
}
else if(s[i]==')'){
while(ctop && st[ctop]!='('){
clc(st[ctop--]);
}
ctop--;
}
}
printf("%d\n",f[][]);
return ;
}

[NOIP2011] 普及组的更多相关文章

  1. NOIP2011 普及组 T3 洛谷P1309 瑞士轮

    今天题做太少,放道小题凑数233 题目背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公 ...

  2. NOIP2011普及组 数字反转

    题目OJ链接: http://codevs.cn/problem/1130/ https://www.luogu.org/problemnew/show/P1307 2011年NOIP全国联赛普及组 ...

  3. [NOIP2011普及组]瑞士轮 JAVA实现

    题目描述 2*N名编号为1~2N的选手共进行R轮比赛.每轮比赛开始前,以及所有比赛结束后,都会按照总分从高到低对选手进行一次排名.选手的总分为第一轮开始前的初始分数加上已参加过的所有比赛的得分和.总分 ...

  4. noip2011普及组——统计单词数

    统计单词数 时间限制:1 s 内存限制:128MB [问题描述]一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数.现在,请你编程实 ...

  5. noip2011普及组——数字反转

    数字反转 时间限制:1s 内存限制:128MB[问题描述]给定一个整数,请将该数各个位上数字反转得到一个新数.新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零 ...

  6. NOIP2011普及组 瑞士环 保序性

    题目链接:http://noi.openjudge.cn/ch0401/4363/ 分析:如果直接模拟,时间复杂度是O(r*nlogn)超时 然后我们发现每次一轮开始时,刚开始是保序的,然后我们可以把 ...

  7. 【单调队列】Vijos P1771 瑞士轮 (NOIP2011普及组第三题)

    题目链接: https://vijos.org/p/1771 题目大意: 给定2N个人(N<=100 000)和其初始分数.能力值(能力两两不同),比赛M次(M<=50),每次PK都是按分 ...

  8. 【解题报告】瑞士轮(NOIP2011普及组T3)

    [题外话:这道题吧……说实话我不太喜欢……因为卡快排.] 题目不贴了,就是给你一个赛制,然后各个选手的初始得分和能力值,问你进行R轮比赛之后第Q名的编号是多少(这个编号读进来就要算OYZ,初始快排的时 ...

  9. NOIP2011普及组 瑞士轮

    OJ地址: https://www.luogu.org/problemnew/show/P1309 http://bailian.openjudge.cn/practice/4031/ 总时间限制:  ...

随机推荐

  1. PHP简单post验证绕过

    if($_POST[user] && $_POST[pass]) { $conn = mysql_connect("*******", "****&quo ...

  2. Android Studio 三种添加插件的方式,androidstudio

    前几篇blog我们介绍了如何安装和配置Android Studio,这篇Blog我们来聊聊如何给Android Studio添加插件,添加插件的路径有三种,我把他们分类如下: 点击设置小按钮 点击[P ...

  3. 使用EditText+ListView并结合TextWatcher实现输入关键字筛选数据

    想必大家应该遇到过这样的情况,当点击Spinner控件后弹出的列表内容超多,一个一个滑动着去寻找所要的项很麻烦,尤其是当自己知道想要选择的内容,这时候如果我们只需要输入某些关键字,就可以讲上百条数据筛 ...

  4. 如何用chrome插件使上网生活更美好-持续更新

    所有插件都可以到Chrome Web Store搜索下载 1.Read Later Fast v-1.6.8 ***刷网页的时候,有很多值得我们阅览但当时木有时间看怎么办? --加可书签啊! ***可 ...

  5. C# Thread.Join()用法的理解 转

    指在一线程里面调用另一线程join方法时,表示将本线程阻塞直至另一线程终止时再执行 比如 1using System; 2 3namespace TestThreadJoin 4{ 5 class P ...

  6. org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter与org.apache.struts.dispatcher.FilterDispatcher是什么区别?

    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter与org.apache.struts.dispatcher.F ...

  7. RDLC系列之二 子报表

    本文实现简单的子报表 一.效果图

  8. WPF数据绑定Binding(二)

    WPF数据绑定Binding(二) 1.UI控件直接的数据绑定 UI对象间的绑定,也是最基本的形式,通常是将源对象Source的某个属性值绑定 (拷贝) 到目标对象Destination的某个属性上. ...

  9. [py]chr ord

    http://www.xuebuyuan.com/2067536.html 也可以help(ord)

  10. 使用Spring.net中对Ado.net的抽象封装来访问数据库

    使用Spring.net中对Ado.net的抽象封装来访问数据库     Spring.NET是一个应用程序框架,其目的是协助开发人员创建企业级的.NET应用程序.它提供了很多方面的功能,比如依赖注入 ...