nenu contest3
http://vjudge.net/contest/view.action?cid=55702#overview
12656 - Almost Palindrome http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4394
先把原串处理成只有小写的,然后枚举每一个位置,可以以它为中心向两边扩展,回文可以是奇数,也可以是偶数,分类讨论,如果两边不一样,那么容量加一,容量小于k都行。
- #include<cstdio>
- #include<cctype>
- const int M=;
- char a[M],b[M];
- int p[M];
- int main(){
- int n,cas=;
- while(~scanf("%d",&n)){
- getchar();
- gets(a);
- int lb=;
- for(int i=;a[i];i++){
- if(isalpha(a[i])){
- p[lb]=i;
- b[lb++]=tolower(a[i]);
- }
- }
- int big=,id;
- for(int i=;i<lb;i++){
- int cnt=;
- for(int j=;i-j>=&&i+j<lb;j++){///奇数
- if(b[i-j]!=b[i+j]) cnt++;
- if(cnt>n) break;
- int prelen=p[i+j]-p[i-j]+;
- if(big<prelen){
- big=prelen;
- id=p[i-j];
- }
- }
- cnt=;
- for(int j=;i-j>=&&i+j+<lb;j++){///偶数
- if(b[i-j]!=b[i+j+]) cnt++;
- if(cnt>n) break;
- int prelen=p[i+j+]-p[i-j]+;
- if(big<prelen){
- big=prelen;
- id=p[i-j];
- }
- }
- }
- printf("Case %d: %d %d\n",cas++,big,id+);
- }
- return ;
- }
12658 - Character Recognition? http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4396
123识别,找不同。
- #include<cstdio>
- char a[][];
- int main(){
- int n;
- while(~scanf("%d",&n)){
- for(int i=;i<;i++){
- scanf("%s",a[i]);
- }
- for(int i=,y=;i<n;i++,y+=){
- if(a[][y]=='.'){
- printf("");
- continue;
- }
- if(a[][y+]=='.'){
- printf("");
- continue;
- }
- printf("");
- }
- puts("");
- }
- return ;
- }
12661 - Funny Car Racing http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4399
bfs,记忆化搜索dp,注意t>a的边就别加了
- #include<cstdio>
- #include<cstring>
- #include<queue>
- #define mt(a,b) memset(a,b,sizeof(a))
- using namespace std;
- typedef long long LL;
- const LL inf=0x3f3f3f3f3f3f3f3fLL;
- const int M=;
- struct G{
- struct E{
- int v,next,a,b,t;
- }e[];
- int le,head[M];
- void init(){
- le=;
- mt(head,-);
- }
- void add(int u,int v,int a,int b,int t){
- e[le].v=v;
- e[le].a=a;
- e[le].b=b;
- e[le].t=t;
- e[le].next=head[u];
- head[u]=le++;
- }
- }g;
- LL dp[M];
- queue<int> q;
- void bfs(int s){
- for(int i=;i<M;i++){
- dp[i]=inf;
- }
- dp[s]=;
- while(!q.empty()) q.pop();
- q.push(s);
- while(!q.empty()){
- int u=q.front();
- q.pop();
- LL pretime=dp[u],cost;
- for(int i=g.head[u];~i;i=g.e[i].next){
- int v=g.e[i].v;
- int a=g.e[i].a;
- int b=g.e[i].b;
- int t=g.e[i].t;
- LL now=pretime%(a+b);
- if(now+t<=a){
- cost=t;
- }
- else{
- cost=a+b-now+t;
- }
- cost+=pretime;
- if(dp[v]>cost){
- dp[v]=cost;
- q.push(v);
- }
- }
- }
- }
- int main(){
- int n,m,s,t,cas=;
- while(~scanf("%d%d%d%d",&n,&m,&s,&t)){
- g.init();
- while(m--){
- int u,v,a,b,c;
- scanf("%d%d%d%d%d",&u,&v,&a,&b,&c);
- if(c>a) continue;
- g.add(u,v,a,b,c);
- }
- bfs(s);
- printf("Case %d: %lld\n",cas++,dp[t]);
- }
- return ;
- }
12662 - Good Teacher http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4400
简单题 注意细节,最坏情况也就是n^2,预处理出最近的。
- #include<cstdio>
- #include<cstring>
- struct G{
- char name[],left[],right[];
- int L,R;
- }g[];
- int main(){
- int n,m,q;
- while(~scanf("%d",&n)){
- for(int i=;i<=n;i++){
- scanf("%s",g[i].name);
- }
- for(int i=;i<=n;i++){
- if(g[i].name[]=='?'){
- int id=i;
- for(int j=i;j<=n;j++){
- if(g[j].name[]!='?'){
- id=j;
- break;
- }
- }
- g[i].R=id-i;
- if(id==i) g[i].R=;
- strcpy(g[i].right,g[id].name);
- id=i;
- for(int j=i;j>=;j--){
- if(g[j].name[]!='?'){
- id=j;
- break;
- }
- }
- g[i].L=i-id;
- if(id==i) g[i].L=;
- strcpy(g[i].left,g[id].name);
- }
- }
- scanf("%d",&m);
- while(m--){
- scanf("%d",&q);
- if(g[q].name[]!='?'){
- puts(g[q].name);
- continue;
- }
- if(g[q].L==g[q].R){
- printf("middle of %s and %s\n",g[q].left,g[q].right);
- continue;
- }
- if(g[q].L<g[q].R){
- for(int i=;i<g[q].L;i++){
- printf("right of ");
- }
- puts(g[q].left);
- continue;
- }
- for(int i=;i<g[q].R;i++){
- printf("left of ");
- }
- puts(g[q].right);
- }
- }
- return ;
- }
12663 - High bridge, low bridge http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4401
离线的区间累加和是可以左++右--on处理的,当然如果是线段树树状数组都会多个logn,不好 不好
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int M=;
- int a[M],lazy[M];
- int main(){
- int n,m,k,cas=;
- while(~scanf("%d%d%d",&n,&m,&k)){
- for(int i=;i<n;i++){
- scanf("%d",&a[i]);
- lazy[i]=;
- }
- sort(a,a+n);
- int prehigh=,nowa,nowb;
- while(m--){
- scanf("%d%d",&nowa,&nowb);
- int s=upper_bound(a,a+n,prehigh)-a;
- int e=upper_bound(a,a+n,nowa)-a;
- lazy[s]++;
- lazy[e]--;
- prehigh=nowb;
- }
- int now=,ans=;
- for(int i=;i<n;i++){
- now+=lazy[i];
- if(now>=k) ans++;
- }
- printf("Case %d: %d\n",cas++,ans);
- }
- return ;
- }
12664 - Interesting Calculator http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4402
听说搜索剪枝能过,因为时限大吧,一开始想二维dp,但是不对,用dp i j 表示第 i 个数在第 j 步到达的最小花费,因为可能一步就加了1,所以第二维也可能达到10^5,完全干不动。 仔细考虑了一下,除了*0这种操作, 其余都会使得当前的数变大。所以当x不等于0时,dp 0 只要1步, 然后从小往大的更新最小费用, 因为除了这种情况 其他的值都是从比自己小的值推过来的。
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- typedef long long LL;
- const LL inf=0x3f3f3f3f3f3f3f3fLL;
- const int M=;
- LL dp[M];
- int step[M];
- int val[][];
- int main(){
- int x,y,cas=;
- while(~scanf("%d%d",&x,&y)){
- for(int i=;i<;i++){
- for(int j=;j<;j++){
- scanf("%d",&val[i][j]);
- }
- }
- for(int i=;i<=y;i++){
- dp[i]=inf;
- step[i]=0x3f3f3f3f;
- }
- dp[x]=;
- step[x]=;
- if(x){
- dp[]=val[][];
- step[]=;
- }
- for(int i=;i<y;i++){
- for(int j=;j<;j++){
- for(int k=;k<;k++){
- int next;
- if(j==){
- next=i*+k;
- }
- else if(j==){
- next=i+k;
- }
- else{
- next=i*k;
- }
- if(next>y) continue;
- LL cost=dp[i]+val[j][k];
- if(dp[next]>cost){
- dp[next]=cost;
- step[next]=step[i]+;
- }
- else if(dp[next]==cost){
- step[next]=min(step[next],step[i]+);
- }
- }
- }
- }
- printf("Case %d: %lld %d\n",cas++,dp[y],step[y]);
- }
- return ;
- }
12665 - Joking with Fermat's Last Theorem http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4403
a,b在1000就够了,所以可以暴力的去判断
- #include<cstdio>
- int x,y,cas=;
- bool ok(int a){
- return a>=x&&a<=y;
- }
- int main(){
- while(~scanf("%d%d",&x,&y)){
- int ans=;
- for(int i=;i<;i++){
- for(int j=;j<;j++){
- if(ok(i)&&ok(j)){
- int left=i*i*i+j*j*j;
- if(left%==){
- int c=left/;
- if(ok(c)){
- ans++;
- }
- }
- }
- }
- }
- printf("Case %d: %d\n",cas++,ans);
- }
- return ;
- }
12667 - Last Blood http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4405
唯一的坑就是如果一个队ac一个题,那要算最早ac的时间。
- #include<cstdio>
- struct G{
- int t,id;
- }g[];
- char p[],yes[];
- bool mat[][];
- int main(){
- int n,t,m,x,y;
- while(~scanf("%d%d%d",&n,&t,&m)){
- for(int i=;i<n;i++){
- g[i].t=-;
- for(int j=;j<=t;j++){
- mat[i][j]=false;
- }
- }
- while(m--){
- scanf("%d%d%s%s",&x,&y,p,yes);
- if(yes[]=='N') continue;
- int pp=p[]-'A';
- if(mat[pp][y]) continue;
- mat[pp][y]=true;
- g[pp].t=x;
- g[pp].id=y;
- }
- for(int i=;i<n;i++){
- printf("%c ",i+'A');
- if(g[i].t!=-){
- printf("%d %d\n",g[i].t,g[i].id);
- }
- else{
- puts("- -");
- }
- }
- }
- return ;
- }
end
nenu contest3的更多相关文章
- nenu contest3 The 5th Zhejiang Provincial Collegiate Programming Contest
ZOJ Problem Set - 2965 Accurately Say "CocaCola"! http://acm.zju.edu.cn/onlinejudge/showP ...
- nenu contest2
http://vjudge.net/vjudge/contest/view.action?cid=54562#overview H B. Polygons http://codeforces.com ...
- nenu contest
http://vjudge.net/vjudge/contest/view.action?cid=54393#overview A n^2能过 对第二个n我二分了一下,快了一点点,nlogn #inc ...
- contest3 CF994 div2 ooxxx? oooox? ooooo?
题意 div2 C (x)(o) 在一个平面上, 给一个水平的正方形和一个\(45^.斜\)的正方形 求是否相交(共点也算), 坐标正负\(100\)以内 div2 D (x)(o) \(A,B\)两 ...
- kgcd ,fmod,fgcd
参考:NENU CS ACM模板made by tiankonguse 2.13 GCD 快速gcd: 位操作没学,真心不懂二进制,还是得学啊 code: int kgcd(){ if(!a || ...
- 嵌入式linux移植LAMP服务器
一.工具准备工作 要想在ARM平台上移植一套Apache+Msql+PHP的Web型服务器. 所用物理机系统: Ubuntu 14.04 LTS(64位) 交叉编译环境: arm-linux-g ...
- IOS平台设计规范
一.UI的控件概述: 1.框架UI的元素分为4类: A:栏:状态栏目和导航栏的结合体; B:内容视图:应用显示的内容信息,包括相关的交互行为,例如滚屏.插入.删除等操作进行排序; C:控制元素:产品行 ...
- 再识C中的结构体
在前面认识C中的结构体中我介绍了结构体的基础知识,下面通过这段代码来回顾一下: #include<stdio.h> #define LEN 20 struct Student{ //定义结 ...
- PVPGN 暗黑破坏神2 1.11b战网配置问题汇总
写了第一篇配置指南之后,很多人向我咨询有关战网搭建的问题.于是觉得很有必要把若干常见的问题,和常用的进阶配置汇总一下,以方便更多人. 1.游戏版本和PVPGN与D2GS版本的问题. PVPGN建议选择 ...
随机推荐
- atoi 实现
int atoi(const char *nptr); 把字符串转换成整型数.ASCII to integer 的缩写. 头文件: #include <stdlib.h> 参数nptr字符 ...
- 2015.1写留言板的时用的 知识点和函数 --->总结
一:时间函数和uniqid() 1:uniqid():生成唯一的id, 无参数返回的字符串的长度为13,有参数为23 2:时间和时间戳相互转换的php函数 ①:time() 返回当前unix的时间戳 ...
- jQuery增加删除修改tab导航特效
HTML: <div class="container iden_top"> <ul> ...
- 设置Linux时间 同步时间
date命令将日期设置为2014年6月18日 ---- date -s 06/18/14 将时间设置为14点20分50秒 ---- date -s 14:20:50 将时间设置为2014年6月 ...
- iis 下的 selfssl
当然,如果你想省掉所有这些麻烦也行,最简单的在IIS启动SSL的方法只要3步: 1. 下载 IIS 6.0 Resource Kit Tools: http://www.microsoft.com/d ...
- easyui获取一行数据和修改data-options的值
<table id="tab" class="easyui-datagrid" style="width: 100%; height: 500p ...
- 原始套接字的简单tcp包嗅探
原始套接字 sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_TCP); while(1) { data_size = recvfrom(sock_raw ...
- Json(2)-DataContractJsonSerializer
public static void DataContractSerializeDemo() { User user = new User { UserID = 1 ...
- Winform上传下载文件代码
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...
- Microsoft Access Database Engine 2010 Redistributable Download
SQL Server 如需要导出类似Excel(*.xls.*.xlsx)格式的数据需要以来以下安装包 Microsoft Access 2010 数据库引擎可再发行程序包 此下载将安装一系列组件,帮 ...