DUT Star Round2
Problems: 开灯问题,问无数次操作之后第n盏灯的状态
Analysis:
cj:平方数有奇数个约数
Tags: Implementation
Problems: 给定一个1..n的全排列,询问区间[l, r]中的数字是否排序后连续
Analysis:
cj:智障的我想了一个及其错误的算法,后来被lucky_ji点醒,if (区间最大值最小值之差 == 区间长度)就好了。。
Return:燃鹅楼上STILL犯了一个有趣的错误,Max-Min+1==Length,当然,区间Max和Min的维护用线段树或者倍增DP就行了
Tags: Data Structure, Dynamic Programming
#include<cstdio>
#include<cstring>
#include<algorithm>
//#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<vector>
using namespace std;
#define INF 2000000000
#define Clear(x, Num) memset(x, Num, sizeof(x))
#define Dig(x) ((x>='0') && (x<='9'))
#define Neg(x) (x=='-')
#define G_c() getchar()
#define Maxn 100010
typedef long long ll; int n, a[Maxn], D_min[Maxn][], D_max[Maxn][], m, l, r; inline int gcd(int x, int y) { if (!y) return x; return gcd(y, x%y); }
inline void read(int &x){ char ch; int N=; while ((ch=G_c()) && (!Dig(ch)) && (!Neg(ch))); if (Neg(ch)) { N=-; while ((ch=G_c()) && (!Dig(ch))); } x=ch-; while ((ch=G_c()) && (Dig(ch))) x=x*+ch-; x*=N; }
//inline void Insert(int u, int v) { To[Cnt]=v; Next[Cnt]=Head[u]; Head[u]=Cnt++; } void rmq_Min()
{
int temp=(int)(log((double)n)/log(2.0));
for(int i=;i<n;i++) D_min[i][]=a[i];
for(int j=;j<=temp;j++)
for(int i=;i<n;i++)
if(i+(<<j)<=n) D_min[i][j]=min(D_min[i][j-], D_min[i+(<<(j-))][j-]);
} void rmq_Max()
{
int temp=(int)(log((double)n)/log(2.0));
for(int i=;i<n;i++) D_max[i][]=a[i];
for(int j=;j<=temp;j++)
for(int i=;i<n;i++)
if(i+(<<j)<=n) D_max[i][j]=max(D_max[i][j-], D_max[i+(<<(j-))][j-]);
} int Minimum(int L, int H)
{
int k=(int)(log((double)H-L+)/log(2.0));
return min(D_min[L][k],D_min[H-(<<k)+][k]);
} int Maximum(int L, int H)
{
int k=(int)(log((double)H-L+)/log(2.0));
return max(D_max[L][k],D_max[H-(<<k)+][k]);
} int main()
{
read(n);
for (int i=; i<n; i++) read(a[i]);
rmq_Min(); rmq_Max();
read(m);
for (int i=; i<=m; i++)
{
read(l); read(r); l--; r--;
int Res=Maximum(l, r)-Minimum(l, r)+;
if (Res==r-l+) puts("YES"); else puts("NO");
}
}
Code By Return
C. ACM群日常禁言一万年
Problems: 秒数转换为xdays, hh/mm/ss
Analysis:
Return:模拟,注意输出格式即可
Tags: Implementation
Problems: 构造长度为n的序列{a},使得LCM(a1, a2, ......, an) = a1 + a2 + ...... + an
Analysis:
Return:首先想到找规律,发现n为奇数时每次在后面加上2*6^k, 3*6^k即可,然后在找n为偶数规律的时候发现,易得下列式子
∑(a_i)=Lcm(a_i) <=> 6*∑(a_i)=6*Lcm(a_i) <=> ∑(a_i*6)=6*Lcm(a_i) <=> 1+2+3+∑(a_i*6)(a_i≠1)=6*Lcm(a_i)
从而发现递推通式,然而,本题坑点在于对a_i的限制,然后发现只有在n=20的时候会Max{a_i}>Limit,从而进一步寻找规律可过
Tags: Math
#include<cstdio>
#include<cstring>
#include<algorithm>
//#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<vector>
using namespace std;
#define INF 2000000000
#define Clear(x, Num) memset(x, Num, sizeof(x))
#define Dig(x) ((x>='0') && (x<='9'))
#define Neg(x) (x=='-')
#define G_c() getchar()
#define Maxn 10010
typedef long long ll; int n, Cnt;
ll S[Maxn]; inline int gcd(int x, int y) { if (!y) return x; return gcd(y, x%y); }
inline void read(int &x){ char ch; int N=; while ((ch=G_c()) && (!Dig(ch)) && (!Neg(ch))); if (Neg(ch)) { N=-; while ((ch=G_c()) && (!Dig(ch))); } x=ch-; while ((ch=G_c()) && (Dig(ch))) x=x*+ch-; x*=N; }
//inline void Insert(int u, int v) { To[Cnt]=v; Next[Cnt]=Head[u]; Head[u]=Cnt++; } int main()
{
while (scanf("%d", &n)!=EOF)
{
if (n==) { puts("3 2 1"); continue; }
S[]=, S[]=, S[]=, S[]=; Cnt=;
while (Cnt<n)
{
for (int i=; i<=Cnt; i++) if ((S[i]!=) && (S[i]!=)) S[i]*=;
S[++Cnt]=;
}
for (int i=; i<=n; i++) printf("%lld ", S[i]); puts("");
}
}
Code By Return
E.小q与面试题
Problems: 维护一个可以查询最小值的栈
Analysis:
cj: 这种题最适合用STL乱搞了
Tags: Data Structure
#define PRON "e"
#include <set>
#include <stack>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll; const int maxn = + ; stack<int> q;
multiset<int> s; char ch;
inline void read(int & x){
int flag = ;
do {
if (ch == '-')
flag = -;
ch = getchar();
} while (!('' <= ch && ch <= '')); x = ;
do {
x = x * + ch - '';
ch = getchar();
} while ('' <= ch && ch <= ''); x *= flag;
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif
s.clear();
while (not q.empty())
q.pop(); int T, a, b, sum = ;
read(T);
while (T --){
read(a);
if (a == ){
read(b);
++ sum;
s.insert(b);
q.push(b);
}
if (a == ){
if (sum == )
puts("ERROR!");
else
printf("%d\n", q.top());
}
if (a == ){
if (sum == )
puts("ERROR!");
else
printf("%d\n", *s.begin());
}
if (a == ){
if (sum == )
puts("ERROR!");
else {
-- sum;
s.erase(s.find(q.top()));
q.pop();
}
}
}
}
Code by cj
Problems: 给定一张n*n的地图,并有m次操作,每次操作为放置炸弹(在砖块上放置视为无效操作),炸弹可以炸掉上下左右最近的砖块,输出最后剩余的砖块数
Analysis:
cj: 直接模拟会Time Limit Exceeded,用row[i]存储第i行的砖块的j坐标,col[j]存储第j行砖块的i坐标。每一次放置炸弹成功后,二分找到前后和左右的砖块并且erase
Tags: Implementation
#define PRON "f"
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; #define lb lower_bound
#define r(y, x) lb(row[y].begin(), row[y].end(), x)
#define c(x, y) lb(col[x].begin(), col[x].end(), y) const int maxn = + ; int n, sum = ;
char s[maxn][maxn];
vector<int> row[maxn], col[maxn]; int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif scanf("%d", &n);
for (int i = ; i < n; i ++){
scanf("%s", s[i]); for (int j = ; j < n; j ++)
if (s[i][j] == '*')
++ sum;
} for (int i = ; i < n; i ++)
for (int j = ; j < n; j ++)
if (s[i][j] == '*')
row[i].push_back(j); for (int j = ; j < n; j ++)
for (int i = ; i < n; i ++)
if (s[i][j] == '*')
col[j].push_back(i); int q, x, y, pos;
scanf("%d", &q);
while (q --){
scanf("%d %d", &y, &x); if ((not row[y].empty() && *(r(y, x)) == x) && (not col[x].empty() && *(c(x, y)) == y))
continue; if (not row[y].empty()){
-- sum;
if (x < *row[y].begin()){
col[*row[y].begin()].erase(c(*row[y].begin(), y));
row[y].erase(row[y].begin());
}
else if (x > *(row[y].end() - )){
col[*(row[y].end() - )].erase(c(*(row[y].end() - ), y));
row[y].erase(row[y].end() - );
}
else {
-- sum;
pos = r(y, x) - row[y].begin();
col[row[y][pos]].erase(c(row[y][pos], y));
col[row[y][pos - ]].erase(c(row[y][pos - ], y)); row[y].erase(pos + row[y].begin());
row[y].erase(pos - + row[y].begin());
}
} if (not col[x].empty()){
-- sum;
if (y < *col[x].begin()){
row[*col[x].begin()].erase(r(*col[x].begin(), x));
col[x].erase(col[x].begin());
}
else if (y > *(col[x].end() - )){
row[*(col[x].end() - )].erase(r(*(col[x].end() - ), x));
col[x].erase(col[x].end() - );
}
else {
-- sum;
pos = c(x, y) - col[x].begin();
row[col[x][pos]].erase(r(col[x][pos], x));
row[col[x][pos - ]].erase(r(col[x][pos - ], x)); col[x].erase(pos + col[x].begin());
col[x].erase(pos - + col[x].begin());
}
} } printf("%d\n", sum);
}
Code by cj
Problems: 题面描述同最基本的数字“正方形”问题
Tags: Dynamic Programming
DUT Star Round2的更多相关文章
- DUT Star Weekly Contest #3 Problem F Solution
		题目链接 问题转化 \[a_i+a_j+(i-j)^2=a_i+i^2+a_j+j^2-2ij\] 令 \(b_i=a_i+i^2\) , 问题化为: 求 \[\max \{b_i+b_j-2ij\} ... 
- 【Star CCM+实例】开发一个简单的计算流程.md
		流程开发在CAE过程中处于非常重要的地位. 主要的作用可能包括: 将一些经过验证的模型隐藏在流程中,提高仿真的可靠性 将流程封装成更友好的界面,降低软件的学习周期 流程开发实际上需要做非常多的工作,尤 ... 
- github中的watch、star、fork的作用
		[转自:http://www.jianshu.com/p/6c366b53ea41] 在每个 github 项目的右上角,都有三个按钮,分别是 watch.star.fork,但是有些刚开始使用 gi ... 
- [deviceone开发]-Star分享的几个示例
		一.简介 这个是star早期分享的几个示例,都非常实用,包括弹出的菜单,模拟支付密码输入等.初学者推荐.也可以直接使用.二.效果图 三.相关下载 https://github.com/do-proje ... 
- 时隔一年再读到the star
		The Star Arthur C. Clarke It is three thousand light-years to the Vatican. Once, I believed that spa ... 
- Github上的Watch和 Star的区别
		Github 推出了新的 Notification 系统,更改了原有的 Watch 机制,为代码库增加了 Star 操作.Notification 将接收 Watching 代码库的动态,包括:* I ... 
- 纯css3 Star
		<style><!--* { box-sizing: border-box; padding: 0px; margin: 0px; } body, html { height: 10 ... 
- Got the Best Employee of the year 2015 Star Award
		Got "The Best Employee of the year 2015 Star Award" from the company, thanks to all that h ... 
- star ccm+ 11.02安装
		STAR CCM+是CD-Adapco公司的主打软件,其安装方式较为简单,这里以图文方式详细描述STAR CCM+11.02安装过程. 1 安装准备工作2 正式安装3 软件破解4 软件测试 1 安装准 ... 
随机推荐
- Spring基本框架
			1.Spring基本框架的概念 Spring 框架是一个分层架构,由 7 个定义良好的模块组成.Spring模块构建在核心容器之上,核心容器定义创建.配置和管理bean的方式.组成Spring框架的每 ... 
- ConCurrent in Practice小记 (2)
			Java-ConCurrent2.html :first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba(0,0,0 ... 
- {Reship}{Code}{CV}
			UIUC的Jia-Bin Huang同学收集了很多计算机视觉方面的代码,链接如下: https://netfiles.uiuc.edu/jbhuang1/www/resources/vision/in ... 
- phpstorm之端点跟踪
			如果在断点没有实时染色,首要请检查local与remote的代码文件的对应. 
- c#轻松实现磁性窗口
			/// <summary>/// 磁性窗体函数/// </summary>/// <param name="form">窗体控件(一般传this ... 
- input[file]标签的accept=”image/*”属性响应很慢的解决办法
			转自:http://blog.csdn.net/lx583274568/article/details/52983693 input[file]标签的accept属性可用于指定上传文件的 MIME类型 ... 
- ListView下拉刷新
			本内容为复制代码: 一.自定义ListView控件: package com.xczl.smart.view; import java.util.Date; import com.suliang.R; ... 
- OpenLDAP,一登录系统就修改密码
			http://guodayong.blog.51cto.com/263451/d-2 郭大勇的博客 1:修改配置文件 在前面打开注释 moduleload ppolicy.la modulepat ... 
- linux服务器加硬盘扩容
			from: http://bbs.chinaunix.net/thread-3613556-1-1.html 试验环境: vmware下,centos6,64位版本,原来系统默认分区,/dev/sda ... 
- c++的默认构造函数 VS 深拷贝(值拷贝) 与 浅拷贝(位拷贝)
			C++默认为类生成了四个缺省函数: A(void); // 缺省的无参数构造函数 A(const A &a); // 缺省的拷贝构造函数 ~A(void); // 缺省的析构函数 A & ... 
