HDU 4594 Script Z

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

一道恶心的模拟,写了一整晚上也不知道哪里错,借助大神的代码AC了

这是Hint :The problem itself is easy of course. But some of the test cases of this problem are strange and annoying. Be careful!

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
int dx[]= {0,1,1,1,0,-1,-1,-1};
int dy[]= {1,1,0,-1,-1,-1,0,1};
int gcd (const LL &a, const LL &b) {return b==0?a:gcd (b,a%b);}
LL LLpow (LL a, LL b) {
    if (b==0) {return 1;}
    LL t=LLpow (a,b/2);
    if (b%2) {return t*t*a;}
    return t*t;
}
using namespace std;
int T,t,n,m;
map<string,string> match[4];
char str[1010],str2[1010],s1[1010],s2[1010];
int type1,type2,Err,Over;
bool Has_Equal() {
    int i,len=strlen (str);
    bool flag=0,flag2=0;
    for (i=0; i<len; i++) {
        if (str[i]==34) {flag2=1;}
        if (str[i]=='=' && flag2==0) {
            flag=true;
            str[i]=' ';
        }
        if (str[i]==9) {str[i]=32;}
    }
    return flag;
}
bool kong() {
    int i,len=strlen (str);
    for (i=0; i<len; i++)
        if (! (str[i]==' ' || str[i]==9) ) {
            return false;
        }
    return true;
}
void solve() {
    int i,len=strlen (str);
    m=0;
    for (i=0; i<len; i++)
        if (str[i]==34) {break;}
    m=i;
    for (i=m; i<len; i++)
        if (! (str[i]==' ' || str[i]==9) ) {str[m++]=str[i];}
    str[m]='\0';
}
int main() {
    string string1,string2;
    scanf ("%d",&T);
    for (t=1; t<=T; t++) {
        if (t!=1) {puts ("");}
        scanf ("%d",&n); getchar();
        for (int i=0; i<=3; i++) {
            match[i].clear();
        }
        Err=1; Over=0;/**Init*/
        while (n--) {
            gets (str);
            solve();
            if (Over==1) {continue;}
            if (kong() ) {continue;}
            if (Has_Equal() ) {
                sscanf (str,"%s %s",s1,s2);
                if (s1[0]=='$') {type1=0;}
                else {type1=1;}
                if (s2[0]!=34) {type2=0;}
                else {type2=1;}
                if (type1==0) {
                    match[0].erase (s1);
                    match[1].erase (s1);
                    match[type2][s1]=s2;
                } else {
                    if (match[2].find (s1) ==match[2].end() && match[3].find (s1) ==match[3].end() ) {
                        match[2+type2][s1]=s2;
                    } else if (Err==1) {
                        printf ("WARNING: Constant %s Already Defined!\n",s1);
                    }
                }
            } else {
                sscanf (str,"%s %s",s1,s2);
                if (s1[0]=='P' && s1[1]=='a') { //Panic
                    printf ("Script was KILLED.\n");
                    Over=1;
                } else if (s1[0]=='E' && s2[1]=='N') { //Errmsg ON
                    Err=1;
                } else if (s1[0]=='E' && s2[1]=='F') { //Errmsg OFF
                    Err=0;
                } else if (s1[0]=='P') { //Print
                    if (s2[0]=='$') {
                        if (match[0].find (s2) !=match[0].end() ) {
                            string1=match[0][s2];
                            cout<<string1<<endl;
                        } else if (match[1].find (s2) !=match[1].end() ) {
                            string1=match[1][s2];
                            string2=string1.substr (1,string1.length()-2);
                            cout<<string2<<endl;
                        } else {
                            printf ("NULL\n");
                            if (Err==1) {
                                printf ("NOTICE: Undefined Variable %s.\n",s2);
                            }
                        }
                    } else {
                        if (match[2].find (s2) !=match[2].end() ) {
                            string1=match[2][s2];
                            cout<<string1<<endl;
                        } else if (match[3].find (s2) !=match[3].end() ) {
                            string1=match[3][s2];
                            string2=string1.substr (1,string1.length()-2);
                            cout<<string2<<endl;
                        } else {
                            printf ("%s\n",s2);
                            if (Err==1) {
                                printf ("NOTICE: Undefined Constant %s.\n",s2);
                            }
                        }
                    }
                } else if (s1[0]=='D') { //Dump
                    if (s2[0]=='$') {
                        if (match[0].find (s2) !=match[0].end() ) {
                            string1=match[0][s2];
                            printf ("integer: ");
                            cout<<string1<<endl;
                        } else if (match[1].find (s2) !=match[1].end() ) {
                            string1=match[1][s2];
                            printf ("string: ");
                            cout<<string1<<endl;
                        } else {
                            printf ("NULL\n");
                            if (Err==1) {
                                printf ("NOTICE: Undefined Variable %s.\n",s2);
                            }
                        }
                    } else {
                        if (match[2].find (s2) !=match[2].end() ) {
                            string1=match[2][s2];
                            printf ("integer: ");
                            cout<<string1<<endl;
                        } else if (match[3].find (s2) !=match[3].end() ) {
                            string1=match[3][s2];
                            printf ("string: ");
                            cout<<string1<<endl;
                        } else {
                            printf ("string: %c%s%c\n",34,s2,34);
                            if (Err==1) {
                                printf ("NOTICE: Undefined Constant %s.\n",s2);
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}



Java开发基于Spring框架的核心技术解析:IOC与AOP原理及Spring MVC应用设计 内容概要:本文档是一份针对初学者的Spring框架整合学习笔记,系统介绍了Spring Framework的核心基础与Spring MVC的开发应用。内容涵盖IOC(控制反转)的基本概念、配置方式与注解使用,详细讲解了bean的生命周期、作用域、依赖注入方式及自动装配机制;深入阐述AOP(面向切面编程)的XML与注解实现,包括切点、通知、织入等核心概念;全面演示Spring MVC的环境搭建、请求处理、参数绑定、视图解析、文件上传、RESTful风格支持、JSON返回、异常处理与拦截器开发;同时包含表单验证、国际化、与Struts2对比以及Spring IOC与MVC整合等实用知识点。; 适合人群:具备Java基础和基本Web开发经验,正在学习或刚进入企业级Java开发领域的初级程序员、应届毕业生及转行人员。; 使用场景及目标:①掌握Spring核心机制如IOC、AOP的原理与实际配置;②能够独立搭建Spring MVC项目并实现常见Web功能如参数接收、响应处理、文件上传、异常统一管理等;③理解Spring生态中各注解的作用与最佳实践,为后续学习Spring Boot和微服务打下坚实基础。; 阅读建议:此资源以理论结合实操为主,建议边阅读边动手搭建项目,重点理解配置背后的运行机制,尤其是bean生命周期、AOP织入过程和MVC请求流程,配合调试加深理解。 立即下载

相关推荐

2026 年高教社杯全国大学生数学建模竞赛A题–药材的烘干问题(数学建模,代码,论文免费分享)

内容概要:本文围绕2026年高教社杯全国大学生数学建模竞赛A题“药材的烘干问题”提供完整的数学建模解决方案,涵盖问题分析、模型构建、算法实现与论文撰写等全套资源。文档不仅深入解析药材烘干过程中的传热传质机理,建立优化模型以提升干燥效率与品质,还系统整合了Matlab、Python等多种编程语言的代码实现方案,并附有高质量论文模板与写作指导。此外,资源包扩展覆盖无线电干扰源定位、微网电力调控、时频冲突消解、SEM广告投放策略等多个赛题,以及信号处理、电力系统优化、车间调度、路径规划、图像处理等多领域科研技术支持,配套提供大量仿真代码、算法模型与网盘资源链接,形成面向数学建模竞赛与科研实践的一站式学习与应用平台。; 适合人群:全国大学生数学建模竞赛参赛者,具备一定数学建模、编程基础的本科及研究生层次学生,以及从事智能优化、信号处理、电力系统、路径规划等相关领域的科研人员与工程技术人员。; 使用场景及目标:①辅助完成数学建模竞赛题目,特别是药材烘干过程的建模与优化求解;②学习多领域典型问题的建模方法与算法实现技巧,如优化算法、机器学习、控制仿真等;③获取标准化论文写作框架与优秀范例,提升科研表达能力与竞赛成绩。; 阅读建议:建议结合文档中提供的代码与论文范例进行实操复现,重点掌握建模逻辑、算法选型与结果分析方法;充分利用网盘资源拓展学习广度,针对自身研究方向深入钻研相关技术细节,全面提升综合实践与创新能力。

Hdu 4594 Difference(奇圈判断+差分约束)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4598 思路:由题意可知两相连点ai符号一定相反,所以若存在奇圈则一定无解。染色,colour[i]==1表示为正,colour[i]==2表示为负。由于(b)条件为充要条件,所以对于图中的点| a[i]-a[j] | >= T,对于非图中点| a[i]-a[j] | = T,否则a[j]-a[i]

哆啦AC梦的博客 951

Script Z - HDU 4594 大模拟

题意:大模拟,说下坑吧。 1. 用HashMap/自写Hash的话就自求多福吧,有专门卡Hash的数据。有队伍的代码TLE,不知道是不是这个原因。 2. Print, Dump, Errmsg, Panic是可以作为常量名的,所以应该先判断是不是赋值式,有很多队伍因为这个而WA掉了。 3. 在双引号中虽不会出现双引号,但是会出现空格。有一部分程序因为空格问题WA掉。 4. Errmsg默认

提比的强行AC 727

HDU 4716 A Computer Graphics Problem (水题)

A Computer Graphics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 43    Accepted Submission(s): 40 Problem Description In this prob...

weixin_34378045的博客 195

HDU 5704 Luck Competition

设自己会选x这个数,那么x就要成为幸运数。 所以可得方程:((sum+x)/n) * (2/3) = x 经过化简,x=2*sum/ (3*n-2) 还需要统计一下和x相同大小数字的个数。 #include #include #include #include #include #include #include #include #include #include #include #i

Kim0403的博客 1194

HDU 5710 Digit-Sum

 5*2=10,S(5*2)=1,2*S(5)=10; 6*2=12,S(6*2)=3,2*S(6)=12; 7*2=14,S(7*2)=5,2*S(7)=14; 8*2=16,S(8*2)=7,2*S(8)=16; 9*2=18,S(9*2)=9,2*S(9)=18; 规律显然,其实就是满十进1,每位数字之和便小了9。 假设n里有L位数为5-9,那么显然满足:S(2n)

Kim0403的博客 956

HDU 5686(斐波那契数列大数)

通过分析,可以发现题目就是一个斐波那契数列,但数很大,所以果断高精度模板。 #include #include #include #include using namespace std; string &_string_add_string (const string &a, const string &b, string &res) { int sum_value =

Kim0403的博客 779

HDU 3363 Ice-sugar Gourd

就两种水果,只要各自数目非偶,那就做不到。 都是偶数,那么一定可以两刀解决问题,维持一个总长一半的区间,使其内水果之一,是它总数的一半。问题解决。 #include #include #include #include #include #include #include #include #include #include #include #include #include #includ

Kim0403的博客 667

HDU 3366 Passage (dp)

 题意:n条通道和m百万元,每一条通道有三种情况,一是直接出去,概率是p,二是碰上士兵,给1百万块再回去,概率是q,或者是死路,概率是1-p-q。问最终出去时最优可能性。 思路:概率dp,既然问最优可能性,肯定是最有可能跑出去的情况最好了,就算跑不出去也要少碰士兵,所以先按p/q从大到小排序,然后dp[i][j]代表在第i个通道,还有j万元的时候能出去的概率。 能直接出去的话,最终结果加

Kim0403的博客 624

HDU 3233 Download Manager

下载不会中断,任务总量一定,网速全程最高。那么,直接除就行,不用模拟。 #include #define CPY(A,B)memcpy(A,B,sizeof(A)) typedef long long LL; typedef unsigned long long uLL; const int MOD=1e9+7; const int INF=0x3f3f3f3f; const LL INFF=0

Kim0403的博客 561

HDU 5702 Solving Order

写个结构体,按数量排序,输出对应颜色。 开始怕有重复来着,觉得先不考虑那种情况,结果过了。 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include

Kim0403的博客 546

HDU 3361 ASCII

 没啥可说,直接按char型输出即可。 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #d

Kim0403的博客 533

HDU 4588 Count The Carries

 从a加到b,统计二进制进位总次数,纯粹暴力,肯定超时。 所以转换成统计从0-a二进制表达的各位1的个数,0-b各位的1的个数,后者减前者对应位,即可求出每位有多少个1。然后当前位1的个数/2,就是当前位的总进位数,后面的加上前一位答案除二,再除二,累加即可推出总数。 那么如何统计每一位上1的个数呢???卡壳卡了两个小时…… 以下是规律:        1       1  1  

Kim0403的博客 533

HDU 3368 Reversi

简单的搜索。详见代码。 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define CPY(A, B) memcpy(A, B, siz

Kim0403的博客 511

HDU 4586 Play the dice (数学期望)

 数学期望就是每次可能结果的概率乘以其结果的总和。 比如1 2 3 4 5 6 数学期望就是3.50. 掷到一个特殊面只是得到了一个再次投掷的机会,和第一次投掷的效果完全一样。特殊面的数值无关紧要。 sum/n*(1+q+q^2+q^3+……+q^k)    q=m/n  k=inf     所以sum/n*(1/(1-m/n))  =  (sum/n)*(n/n-m)  =sum

Kim0403的博客 510

HDU 5706 GirlCat

搜索题,简单DFS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define CPY(A, B) memcpy(A,

Kim0403的博客 494

HDU 3232 Crossing Rivers (数学期望)

船的初始位置随机,要求期望。 那么船从河上正好往东岸赶的几率是1/2,往西岸去再回来的几率是1/2 #include #define CPY(A,B)memcpy(A,B,sizeof(A)) typedef long long LL; typedef unsigned long long uLL; const int MOD=1e9+7; const int INF=0x3f3f3f3f;

Kim0403的博客 489

HDU 3697 Selecting courses

暴力,贪心 每门课按结束时间从小到大排序,结束时间相同的按开始时间从小到大排序,这样按顺序选一定最优。 由题意可知,这个人开始选课的时间自由,一旦开始选课,只能每五分钟选一次,开始时间分别取0,、1、2、3、4,剩下的选课时间就固定了,暴力查找一下即可。 #include #include #include #include #include #include #include #inclu

Kim0403的博客 474
上一篇: HDU 3366 Passage (dp)
下一篇: CodeForces 288C Polo the Penguin and XOR operation
Kim0403
博客等级 码龄12年 25粉丝 132原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值