zoukankan      html  css  js  c++  java
  • UVALive

    /*
      这题我觉得最关键的地方不在写代码,而是看懂题意,我读题时,其实是没那么快理解题目是要我们做什么的
      
      以及,值得一提的是,之前我一直以为,应该把last记录下来,但是后来发现根本没有必要,直接记录下ans就行,每次遇到S,ans更新,遇到非S的字母和为1的数组,ans更新,和非1的数字一点关系都没有,换言之,1后面的数字不一定要满足 1 2 3 4这种关系,如果我是1 3 5,也可以算作一个pattern,下次遇到数字1或者字母S,才相当于进入下一个pattern
      
      以及,这个点是在看这个blog时发现的,这个博主看问题真是一眼看到本质...
      http://blog.csdn.net/kim0403/article/details/52144271
      
      于是发现,这题根本就不需要记录上一个数字啊...我果然还是题目做太少了,sigh
    */


    #include<iostream>
    using namespace std;
    //#define debug
    
    int main()
    {
    	#ifdef debug 
    	freopen("E:\in.txt", "r", stdin);
    	freopen("E:\out.txt", "w", stdout);
    	#endif
    	
    	int n, num, last, ans = 0;
    	string str;
    	while (cin >> n)
    	{
    		last = 0, ans = 0;
    		while (n--)
    		{
    			cin >> str;
    			if (str != "S") 
    			{
    				cin >> num;
    				if (num == 1) ans++, last = 1;
    				else if (num == last + 1) last++;
    			}
    			else
    			ans++, last = 0;
    		}
    		cout << ans << endl;
    	}
    	
    	#ifdef debug
    	fclose(stdin);
    	fclose(stdout);
    	#endif
    
    	return 0;
    }


  • 相关阅读:
    mysql 赋给用户权限 grant all privileges on
    ubuntu下aptget安装小型的lamp环境
    Linux系统进程管理
    SQLChapter1_Overview of SQL Server
    SQLChapter2Querying Data
    SQLexercise
    SQLChapter4Managing Databases and Table
    JavaUI添加事件(二)
    java ActionEventDemo
    JavaUI弹出对话框
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789545.html
Copyright © 2011-2022 走看看