NOIP2013普及组
T1】记数问题
试计算在区间1 到n 的所有整数中,数字x(0 ≤ x ≤ 9)共出现了多少次?例如,在1到11 中,即在1、2、3、4、5、6、7、8、9、10、11中,数字1 出现了4 次。
其实这个问题也很经典了。。。
别想很复杂,其实打暴力完全OK
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int maxn=1010;
const int INF=0x3fffffff; int n,x;
int main(){
cin>>n>>x;
int ans=0;
for(int i=1;i<=n;i++){
int temp=i;
while(temp){
if(temp%10==x) ans++;
temp/=10;
}
}
cout<<ans<<endl;
return 0;
}
T2】表达式求值

这种题也是经典题
但是这下面是一种很...奇妙的做法
在加法那里处理还没处理完的乘法
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int maxn=1010;
const int INF=0x3fffffff;
//简单化的表达式求值
//只有加、乘
/*
stack<long long> num;
stack<char> op;
char a[100001];
int lev(char x){ //计算优先级
if(x=='+') return 1;
if(x=='*') return 2;
return 0;
}
void js(stack<long long> &num,stack<char> &op){
int y=num.top();
num.pop();
int x=num.top();
num.pop();
char xx=op.top();
op.pop();
if(xx=='+') num.push((x+y)%10000);
else num.push((x*y)%10000);
}
*/
//下面的这个写法不知道为什么超时了
//管他的,用一种简单的特殊写法
int last;
char c;
int x,a=0,b=1,sum=0;
int main(){
int i,j;
bool flag=1;
do{
if(cin>>c);
else{
flag=0;
c='+'; //在最后补一个+号
}
if(c>='0'&&c<='9'){
x=x*10+c-'0';
}
else{
a=x;
x=0;
}
if(c=='*'){
last=1;
b=(a*b)%10000; //处理乘数
}
if(c=='+'){
if(last){
a=(a*b)%10000; //a是另一个乘数
sum=(sum+a)%10000;
b=1;
last=0;
}
else sum+=a;
}
}while(flag);
cout<<sum%10000<<endl; return 0;
} /*
int main(){
scanf("%s",a+1);
int len=strlen(a+1);
bool flag=0;
long long temp=0;
for(int i=1;i<=len;i++){
if(a[i]>='0'&&a[i]<='9'){
temp=temp*10+a[i]-'0';
flag=true;
}
else{
if(flag){
num.push(temp);
temp=0;
flag=false;
}
while(!op.empty()&&(lev(op.top())>=lev(a[i]))) js(num,op);
op.push(a[i]);
} }
if(flag){
num.push(temp);
temp=0;
flag=false;
}
while(!op.empty()){
js(num,op);
}
cout<<num.top()%10000<<endl;
return 0;
} */
T3 小朋友的数字

这道题涉及到一个细节,取余所导致的结果不同和太大值之间的问题
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int maxn=1000001;
const int INF=0x3fffffff;
long long res[maxn],d[maxn],dp[maxn];
//d[i]是特征值,res是得分,dp是前i项的和,dp[i]=max(0,dp[i-1])+x
//d[i]=max(d[i-1],dp[i]) res[i]=max(res[i-1],res[i-1]+d[i-1])
long long n,p;
//但是注意结果有20分拿不到,因为数据范围,如果在计算过程种可能会超过Long long,所以必须边算边取模
//但是取模就无法比较最大值,所以不能直接用Max,但是从第二个人开始分数是没有下降的,所以再运算过程种如果超过Longlong就可以去模
//因为res[1]是不超过long long的,所以在运算过程中一旦超过long long就说明是最大的是res[n], int main(){
cin>>n>>p;
int x;
dp[0]=0;
for(int i=1;i<=n;i++){
cin>>x;
dp[i]=max(0LL,dp[i-1])+x; //0后面要加LL
if(i==1) {
d[i]=dp[i];
}
else{
d[i]=max(d[i-1],dp[i]);
}
}
res[1]=d[1];
res[2]=d[1]+dp[1];
bool flag=0; //判断在n>=3的过程中,有没有超过long long
for(int i=3;i<=n;i++){
res[i]=max(res[i-1],res[i-1]+d[i-1]);
if(res[i]>1e9){
flag=1;
res[i]=res[i]%p;
}
}
if(flag) cout<<res[n]%p<<endl;
else cout<<max(res[1],res[n])%p<<endl;
return 0;
}
T4】车站分级

想不到是考图吧哈哈哈,但是这道题的连线端点要注意,从小的指向大的,是在从经过的车站之间没停靠的车站都是明确小于的,所以可以连线
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int maxn=1010;
const int INF=0x3fffffff;
//这道题是考图,经过大于等于比当前等级的车站,就能总结出比当前等级小的和大的,让小的指向大的
//再拓扑排序,及查找深度,就能够得出至少深度得多少
int n,m;
int to[maxn],in[maxn],mapp[maxn][maxn];
int temp[maxn],vis[maxn];
int main(){
cin>>n>>m;
int num;
for(int i=1;i<=m;i++){
cin>>num;
int x,t=0,l,r;
memset(temp,0,sizeof(temp));
memset(vis,0,sizeof(vis));
memset(to,0,sizeof(to));
for(int j=1;j<=num;j++){
cin>>x;
if(j==1) l=x;
if(j==num) r=x;
temp[j]=x;vis[x]=1;
}
for(int z=l;z<=r;z++){
if(vis[z]==0){
to[++t]=z;
}
}
//把小的都指向大的
for(int j=1;j<=t;j++){
for(int z=1;z<=num;z++) mapp[to[j]][temp[z]]=1;
}
}
//下面初始化入度
for(int i=1;i<=n;i++){
in[i]=0;
for(int j=1;j<=n;j++) if(mapp[j][i]) in[i]++;
}
int ans=1;
memset(temp,0,sizeof(temp));
while(true){
bool f=0;
for(int i=1;i<=n;i++){
temp[i]=in[i];
}
for(int i=1;i<=n;i++){
if(temp[i]==0) {
for(int j=1;j<=n;j++){
if(mapp[i][j]){
mapp[i][j]=0;
in[j]--;
}
}
}
else f=1; //如果没有说明还需要继续循环
} if(f==0) break; //如果没有更新了就可以退出
ans++;
}
cout<<ans<<endl;
return 0;
}
NOIP2013普及组的更多相关文章
- [NOIP2013] 普及组
计数问题 纯模拟 #include<cstdio> #include<iostream> using namespace std; int main(){ int n,x; c ...
- NOIP2013普及组 -SilverN
T1 计数问题 题目描述 试计算在区间 1 到 n 的所有整数中,数字 x(0 ≤ x ≤ 9)共出现了多少次?例如,在 1 到 11 中,即在 1.2.3.4.5.6.7.8.9.10.11 中, ...
- NOIP2013普及组 T2 表达式求值
OJ地址:洛谷P1981 CODEVS 3292 正常写法是用栈 #include<iostream> #include<algorithm> #include<cmat ...
- 【NOIP2013 普及组】车站分级
[NOIP2013 普及组]车站分级 一.题目 [NOIP2013 普及组]车站分级 时间限制: 1 Sec 内存限制: 128 MB 提交: 3 解决: 0 [提交][状态][讨论版] 题目描述 ...
- [NOIP2013 普及组] 表达式求值
[NOIP2013 普及组] 表达式求值 给定一个只包含加法和乘法的算术表达式,请你编程计算表达式的值. Input 一行,为需要你计算的表达式,表达式中只包含数字.加法运算符"+" ...
- [NOIp2013普及组]车站分级
思路: 对于每一趟车,将区间内所有经停的站和所有未经停的站连一条边,表示前者优先级一定高于后者,然后用Kahn跑一遍拓扑排序即可.然而这样会创造大量多余的边,会TLE1个点.考虑一种优化:因为每趟车本 ...
- Noip2013(普及组) 车站分级
题目描述 一条单向的铁路线上,依次有编号为 , , …, n 的 n 个火车站.每个火车站都有一个级别,最低为 级.现有若干趟车次在这条线路上行驶,每一趟都满足如下要求:如果这趟车次停靠了火车站 x, ...
- 洛谷——P1980 [NOIP2013 普及组] 计数问题
题目描述 试计算在区间 11 到 nn的所有整数中,数字x(0 ≤ x ≤ 9)x(0≤x≤9)共出现了多少次?例如,在 11到1111中,即在 1,2,3,4,5,6,7,8,9,10,111,2, ...
- NOIP2002-2017普及组题解
虽然普及组一般都是暴力省一,但是有一些题目还是挺难的qwq个人觉得能进TG的题目会在前面打上'*' NOIP2002(clear) #include<bits/stdc++.h> usin ...
- NOIP2012 普及组 T3 摆花——S.B.S.
题目描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时 ...
随机推荐
- RepOpt-VGG:梯度参数化的开创
本文来自公众号"AI大道理" YOLov6的量化问题: yolov6在结构中大量使用了重参数结构,导致数据分布过差,PTQ精度急剧下降.另外,重参数化结构网络无法直接使用Q ...
- 【Anaconda】为右键菜单添加“当前位置开启Anaconda Prompt”
Stack Overflow 上查找到该解决方法:『Adding "Open Anaconda Prompt here" to context menu (Windows) - S ...
- Android NDK build vsomeip3
Build Boost for Android https://github.com/moritz-wundke/Boost-for-Android set the NDK_ROOT environm ...
- JSP课设:学生选课系统(附源码+调试)
JSP学生选课管理系统学生选课管理系统功能概述(1)登录模块分为两种角色:学生角色.教师角色 (2)教师模块:选课管理功能为对课程信息(课程编号.名称.学分)进行添加.修改.删除操作:学生信息功能对学 ...
- 利用 fastjson 的 toJSONStringWithDateFormat 方法,将Date 格式化 为常见类型的时间
利用 fastjson 的 toJSONStringWithDateFormat 方法,将Date 格式化 为常见类型的时间 JSON.toJSONStringWithDateFormat(nrcSt ...
- 串口USART(续二)
通过前面的分析知道,在LPC824中,USART所拥有的配置寄存器有很多,但在一般情况下,如果只是简单地使用收发功能,则只需要使用到配置寄存器CFG.波特率发生器寄存器BRG.中断使能读取和置位寄存器 ...
- 397. 整数替换 (Medium
问题描述 397. 整数替换 (Medium) 给定一个正整数 n ,你可以做如下操作: 如果 n 是偶数,则用 n / 2 替换 n. 如果 n 是奇数,则可以用 n + 1 或 n - 1 替换 ...
- zabbix(历史数据保留时长和趋势存储时间的区别)
zabbix(历史数据保留时长和趋势存储时间的区别)? zabbix(历史数据保留时长和趋势存储时间分别影响着哪里)? 001.影响grafana 数据展示的是历史数据还是趋势数据? 等把<历史 ...
- echarts的label的formatter 自动换行
1.加 \n 2.使用extraCssText
- etcd使用Cfssl生成自签证书(pem)
CFSSL是CloudFlare开源的一款PKI/TLS工具,CFSSL包含一个命令行工具和一个用于签名,验证并且捆绑TLS证书的HTTP API服务,环境构建方面需要 Go 1.12+. 需要两套证 ...