2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A Cache Simulator
来源:互联网 发布:js 种修改input的宽度 编辑:程序博客网 时间:2024/05/20 03:47
Cache memories have been used widely in current microprocessor systems. In this problem, you are asked to write a program for a cache simulator. The cache has the following metrics:
1. The cache size is 1 KB (K-byte).
2. The cache uses the direct mapped approach.
3. The cache line size is 16 bytes.
4. The cacheable memory size is 256MB.
Your program will report a hit or miss when an address is given to the cache simulator. This is often called trace simulation. Initially, all of the cache lines are in the invalid state. When a memory line is first brought into the cache, the allocated cache entry transits into the valid state. Assume that a miss causes the filling of a whole cache line.
Input Format
Up to 100 lines of address can be given in the file. Each line consists of an address given to the simulator. The address is given in hexadecimal form. We assume that each address references only one byte of data. The input file ends at the line with the word END.
Output Format
Report either Hit or Miss for each of the given addresses. The last line reports cache hit ratio in percentage, that is, the number of hits divided by the number of total addresses given.
样例输入
AAAA00000010B200010BAEND
样例输出
MissMissHitHit ratio = 33.33%
题目来源
2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
这个题读不懂,一点不懂,计算机原理这门课抢了两学期没抢到这门课,我能怎么办,我也是很绝望啊!要说有注意的地方就是END的判断了,不能判断单独的E,也不能判断单独的D,也不能挑出ED判断,可以判断第二个N。
代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=100005;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}int main(){int ans[1024];char map[15];int cnt=0,sum=0,i,j,k,temp,x;mset(ans,-1);while(cin>>map){if(map[1]=='N'){printf("Hit ratio = %.2f%%\n",cnt*100.0/sum);break;}sscanf(map,"%x",&temp); //输入字符串转换为十六进制,赋值给temp temp-=temp%16;x=temp%1024;x-=x%16;if(ans[x]!=temp){cout<<"Miss"<<endl;;ans[x]=temp;}else{cout<<"Hit"<<endl;cnt++;}sum++;}return 0;}
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 H. A Cache Simulator
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A Cache Simulator
- A Cache Simulator 组成原理 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 H A Cache Simulator
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A. Weather Patterns(阅读题)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A. Weather Patterns
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A Weather Patterns(阅读理解)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Minimum Distance in a Star Graph
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A Weather Patterns
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- ACM 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛(J.Minimum Distance in a Star Graph)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛- J. Minimum Distance in a Star Graph
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J. Minimum Distance in a Star Graph
- Minimum Distance in a Star Graph BFS/康托展开 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J Minimum Distance in a Star Graph 广度优先搜索
- 为Druid监控配置访问权限(配置访问监控信息的用户与密码)
- CGI 与 WSGI
- Java字符串String详解
- mysql创建用户和数据库
- 高二&高一&初三模拟赛19 总结
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 A Cache Simulator
- murmur5
- Java多线程
- 1826: [JSOI2010]缓存交换
- POJ题目分类(很好很富有层次感)ACM进阶之路
- Linux下安装redis
- 无旋treap启发式搜索 [HNOI2012]永无乡
- Kubernetes文档阅读01-文档主页
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem